mechanize 2.11.0 → 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: b4c0419c6395467b67e04d02f6fad693555635888226463874b23836dd481f74
4
- data.tar.gz: e9787a25ee371a1f9c5918c49cab30c89d6fb375ca1e6fffc7b444bc5dc5f7e1
3
+ metadata.gz: 991701dfb3f8c11d731e22733ddb6bd158303ff68b3701d8fdcd780228cbc4be
4
+ data.tar.gz: 53d0f50ac55ec64c3accc35f69c828477ba2c5efe36921711e8adea1c459da05
5
5
  SHA512:
6
- metadata.gz: 23436f8664e13b44f71d5abb2b7b29a0a309e76880503c6ac68c19e1258d3e0dd73919f4b407f0dcfb3fe04dfeea0a350c0fcc967c2fee13085a69aa71992084
7
- data.tar.gz: 9869c25e459212cbff34f11e0cadcc985fff6e97bfad5012c091a9c594dd9a58ba2bc4afb7fed50c089cbe943a3adb9528968e80df01803869709508aaf9d218
6
+ metadata.gz: edde84f61a68ae2461b621b02e20dc479cab2258f8d005a3a6304f0c18d8829ae9e40c01c4d3f2eef0f24d08cc046035c1432a8b16202095a46f55ed67788fc5
7
+ data.tar.gz: 2bdbed0e937a610002095df60ad1bb476f5ddfe521b97044a4dd4102558ddf5a890a5a335fd3f6cb89be1403e91461f7db97ec0f924b3d6c21c95bf837834fd6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## 2.11.0 / 2024-07-18
4
9
 
5
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
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
@@ -831,6 +859,8 @@ class Mechanize::HTTP::Agent
831
859
  content_encoding_inflate body_io
832
860
  when 'gzip', 'x-gzip' then
833
861
  content_encoding_gunzip body_io
862
+ when 'br' then
863
+ content_encoding_brotli body_io
834
864
  else
835
865
  raise Mechanize::Error,
836
866
  "unsupported content-encoding: #{response['Content-Encoding']}"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Mechanize
3
- VERSION = "2.11.0"
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
 
@@ -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.11.0
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-07-18 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,