mechanize 2.10.1 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5d4ec84463a2df7945cede673dde4ea74d9f03270c923cd7f11d2fbc56aadcd
4
- data.tar.gz: c5803f307bc7924da28191b6cfee4a9ce2ed4e9f5daeeee3e3cc9e38bd405cfc
3
+ metadata.gz: 991701dfb3f8c11d731e22733ddb6bd158303ff68b3701d8fdcd780228cbc4be
4
+ data.tar.gz: 53d0f50ac55ec64c3accc35f69c828477ba2c5efe36921711e8adea1c459da05
5
5
  SHA512:
6
- metadata.gz: 87f463a89c2158edfce7b556e3b824a6215646c6581947c434df8e7289f2e150a986db1750d5336b9266b7aee768f4000903271472575edcb90008862071818b
7
- data.tar.gz: 5787421c7c331be9f0adc25ae01587a88ae8c78786420113aa813a9bbddc4ea755655501add2a7afc0400c03d5f9bdfb041958c5ebc61815981c0dac084296fb
6
+ metadata.gz: edde84f61a68ae2461b621b02e20dc479cab2258f8d005a3a6304f0c18d8829ae9e40c01c4d3f2eef0f24d08cc046035c1432a8b16202095a46f55ed67788fc5
7
+ data.tar.gz: 2bdbed0e937a610002095df60ad1bb476f5ddfe521b97044a4dd4102558ddf5a890a5a335fd3f6cb89be1403e91461f7db97ec0f924b3d6c21c95bf837834fd6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Mechanize CHANGELOG
2
2
 
3
+ ## 2.12.0 / 2024-07-29
4
+
5
+ * Introduce experimental support for handling Brotli-compressed responses (CRuby only). (#650) @weshatheleopard
6
+
7
+
8
+ ## 2.11.0 / 2024-07-18
9
+
10
+ * The `accept-charset` header is no longer sent. In early versions of Mechanize, circa 2007, this was a common header but now no modern browser sends it, and servers are instructed to ignore it. See #646 for an example of a server that is confused by its presence. (#647) @flavorjones
11
+
12
+
3
13
  ## 2.10.1 / 2024-06-12
4
14
 
5
15
  * Improve page encoding error recovery on pages with broken encoding when used with libxml2 >= 2.12.0. (#644) @flavorjones
data/Gemfile CHANGED
@@ -1,3 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "minitest", "~> 5.14"
6
+ gem "rake", "~> 13.0"
7
+ gem "rdoc", "~> 6.3"
8
+ gem "rubocop", "~> 1.12"
9
+ gem "brotli", ">= 0.5" unless RUBY_PLATFORM == "java"
@@ -495,6 +495,34 @@ class Mechanize::HTTP::Agent
495
495
  body_io.close
496
496
  end
497
497
 
498
+ ##
499
+ # Decodes a Brotli-encoded +body_io+
500
+ #
501
+ # (Experimental, CRuby only) Although Mechanize will never request a Brotli-encoded response via
502
+ # `accept-encoding`, buggy servers may return brotli-encoded responses anyway. Let's try to handle
503
+ # that case if the Brotli gem is loaded.
504
+ #
505
+ # If you need to handle Brotli-encoded responses, install the 'brotli' gem and require it in your
506
+ # application. If the `Brotli` constant is defined, Mechanize will attempt to use it to inflate
507
+ # the response.
508
+ #
509
+ def content_encoding_brotli(body_io)
510
+ log.debug('deflate brotli body') if log
511
+
512
+ unless defined?(::Brotli)
513
+ raise Mechanize::Error, "cannot deflate brotli-encoded response. Please install and require the 'brotli' gem."
514
+ end
515
+
516
+ begin
517
+ return StringIO.new(Brotli.inflate(body_io.read))
518
+ rescue Brotli::Error
519
+ log.error("unable to brotli-inflate response") if log
520
+ raise Mechanize::Error, "error inflating brotli-encoded response."
521
+ end
522
+ ensure
523
+ body_io.close
524
+ end
525
+
498
526
  def disable_keep_alive request
499
527
  request['connection'] = 'close' unless @keep_alive
500
528
  end
@@ -581,7 +609,6 @@ class Mechanize::HTTP::Agent
581
609
  end
582
610
 
583
611
  def request_language_charset request
584
- request['accept-charset'] = 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'
585
612
  request['accept-language'] = 'en-us,en;q=0.5'
586
613
  end
587
614
 
@@ -832,6 +859,8 @@ class Mechanize::HTTP::Agent
832
859
  content_encoding_inflate body_io
833
860
  when 'gzip', 'x-gzip' then
834
861
  content_encoding_gunzip body_io
862
+ when 'br' then
863
+ content_encoding_brotli body_io
835
864
  else
836
865
  raise Mechanize::Error,
837
866
  "unsupported content-encoding: #{response['Content-Encoding']}"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Mechanize
3
- VERSION = "2.10.1"
3
+ VERSION = "2.12.0"
4
4
  end
data/mechanize.gemspec CHANGED
@@ -71,9 +71,4 @@ Gem::Specification.new do |spec|
71
71
  spec.add_runtime_dependency("rubyntlm", ">= 0.6.3", "~> 0.6")
72
72
  spec.add_runtime_dependency("base64") # removed from bundled gems in 3.4, and needed by rubyntlm (which doesn't declare this dependency)
73
73
  spec.add_runtime_dependency("nkf") # removed from bundled gems in 3.4
74
-
75
- spec.add_development_dependency("minitest", "~> 5.14")
76
- spec.add_development_dependency("rake", "~> 13.0")
77
- spec.add_development_dependency("rdoc", "~> 6.3")
78
- spec.add_development_dependency("rubocop", "~> 1.12")
79
74
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'mechanize/test_case'
5
+ require "brotli" unless RUBY_PLATFORM == "java"
5
6
 
6
7
  class TestMechanizeHttpAgent < Mechanize::TestCase
7
8
 
@@ -576,8 +577,8 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
576
577
  def test_request_language_charset
577
578
  @agent.request_language_charset @req
578
579
 
579
- assert_equal 'en-us,en;q=0.5', @req['accept-language']
580
- assert_equal 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', @req['accept-charset']
580
+ assert_equal('en-us,en;q=0.5', @req['accept-language'])
581
+ assert_nil(@req['accept-charset'])
581
582
  end
582
583
 
583
584
  def test_request_referer
@@ -924,6 +925,46 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
924
925
  assert_equal 'part', body.read
925
926
  end
926
927
 
928
+ def test_response_content_encoding_brotli_when_brotli_not_loaded
929
+ skip("only test this on jruby which doesn't have brotli support") unless RUBY_ENGINE == 'jruby'
930
+
931
+ @res.instance_variable_set :@header, 'content-encoding' => %w[br]
932
+ body_io = StringIO.new("content doesn't matter for this test")
933
+
934
+ e = assert_raises(Mechanize::Error) do
935
+ @agent.response_content_encoding(@res, body_io)
936
+ end
937
+ assert_includes(e.message, "cannot deflate brotli-encoded response")
938
+
939
+ assert(body_io.closed?)
940
+ end
941
+
942
+ def test_response_content_encoding_brotli
943
+ skip("jruby does not have brotli support") if RUBY_ENGINE == 'jruby'
944
+
945
+ @res.instance_variable_set :@header, 'content-encoding' => %w[br]
946
+ body_io = StringIO.new(Brotli.deflate("this is compressed by brotli"))
947
+
948
+ body = @agent.response_content_encoding(@res, body_io)
949
+
950
+ assert_equal("this is compressed by brotli", body.read)
951
+ assert(body_io.closed?)
952
+ end
953
+
954
+ def test_response_content_encoding_brotli_corrupt
955
+ skip("jruby does not have brotli support") if RUBY_ENGINE == 'jruby'
956
+
957
+ @res.instance_variable_set :@header, 'content-encoding' => %w[br]
958
+ body_io = StringIO.new("not a brotli payload")
959
+
960
+ e = assert_raises(Mechanize::Error) do
961
+ @agent.response_content_encoding(@res, body_io)
962
+ end
963
+ assert_includes(e.message, "error inflating brotli-encoded response")
964
+ assert_kind_of(Brotli::Error, e.cause)
965
+ assert(body_io.closed?)
966
+ end
967
+
927
968
  def test_response_content_encoding_gzip_corrupt
928
969
  log = StringIO.new
929
970
  logger = Logger.new log
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.1
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-06-12 00:00:00.000000000 Z
15
+ date: 2024-07-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: addressable
@@ -218,62 +218,6 @@ dependencies:
218
218
  - - ">="
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
- - !ruby/object:Gem::Dependency
222
- name: minitest
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - "~>"
226
- - !ruby/object:Gem::Version
227
- version: '5.14'
228
- type: :development
229
- prerelease: false
230
- version_requirements: !ruby/object:Gem::Requirement
231
- requirements:
232
- - - "~>"
233
- - !ruby/object:Gem::Version
234
- version: '5.14'
235
- - !ruby/object:Gem::Dependency
236
- name: rake
237
- requirement: !ruby/object:Gem::Requirement
238
- requirements:
239
- - - "~>"
240
- - !ruby/object:Gem::Version
241
- version: '13.0'
242
- type: :development
243
- prerelease: false
244
- version_requirements: !ruby/object:Gem::Requirement
245
- requirements:
246
- - - "~>"
247
- - !ruby/object:Gem::Version
248
- version: '13.0'
249
- - !ruby/object:Gem::Dependency
250
- name: rdoc
251
- requirement: !ruby/object:Gem::Requirement
252
- requirements:
253
- - - "~>"
254
- - !ruby/object:Gem::Version
255
- version: '6.3'
256
- type: :development
257
- prerelease: false
258
- version_requirements: !ruby/object:Gem::Requirement
259
- requirements:
260
- - - "~>"
261
- - !ruby/object:Gem::Version
262
- version: '6.3'
263
- - !ruby/object:Gem::Dependency
264
- name: rubocop
265
- requirement: !ruby/object:Gem::Requirement
266
- requirements:
267
- - - "~>"
268
- - !ruby/object:Gem::Version
269
- version: '1.12'
270
- type: :development
271
- prerelease: false
272
- version_requirements: !ruby/object:Gem::Requirement
273
- requirements:
274
- - - "~>"
275
- - !ruby/object:Gem::Version
276
- version: '1.12'
277
221
  description: |-
278
222
  The Mechanize library is used for automating interaction with websites.
279
223
  Mechanize automatically stores and sends cookies, follows redirects,