mechanize 2.12.0 → 2.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +4 -1
- data/lib/mechanize/http/agent.rb +31 -0
- data/lib/mechanize/pluggable_parsers.rb +1 -1
- data/lib/mechanize/test_case.rb +0 -5
- data/lib/mechanize/version.rb +1 -1
- data/mechanize.gemspec +1 -1
- data/test/test_mechanize_http_agent.rb +44 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f6963774d1167e4fd1a9a48252dc9aa30333b46bdaba1319b9bc8dac2e0796
|
4
|
+
data.tar.gz: fbbb2f82727a36f58313dfca7ffe4d5f1a5b33024663cd501cebdb5515831e56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 339bd5bb87e66aad70541bd0a1a9031f349f6fbe62d991c45b28ebae43d9d4db7d4ba31c15de8578ca86e5c0efa0593730075e3695fc3e412f87ba07e6529447
|
7
|
+
data.tar.gz: 7e629b20b4760f9e7b701e9cbad275f21cd6bba5114f8538ea9607f1a2335e9f1e121d1c0f36cba1027889f8486afe0aa5e10edff9d0b371fb0c0adf24277059
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Mechanize CHANGELOG
|
2
2
|
|
3
|
+
## 2.12.2 / 2023-10-02
|
4
|
+
|
5
|
+
* Quash warnings from `Mime::Type.new` in `mime-types` v3.6.0. (#655) @avk
|
6
|
+
|
7
|
+
|
8
|
+
## 2.12.1 / 2024-08-21
|
9
|
+
|
10
|
+
* Introduce experimental support for handling Zstd-compressed responses (CRuby only). (#652) @adrianodennanni
|
11
|
+
|
12
|
+
|
3
13
|
## 2.12.0 / 2024-07-29
|
4
14
|
|
5
15
|
* Introduce experimental support for handling Brotli-compressed responses (CRuby only). (#650) @weshatheleopard
|
data/Gemfile
CHANGED
data/lib/mechanize/http/agent.rb
CHANGED
@@ -523,6 +523,35 @@ class Mechanize::HTTP::Agent
|
|
523
523
|
body_io.close
|
524
524
|
end
|
525
525
|
|
526
|
+
##
|
527
|
+
# Decodes a Zstd-encoded +body_io+
|
528
|
+
#
|
529
|
+
# (Experimental, CRuby only) Although Mechanize will never request a zstd-encoded response via
|
530
|
+
# `accept-encoding`, buggy servers may return zstd-encoded responses, or you might need to
|
531
|
+
# inform the zstd keyword on your Accept-Encoding headers. Let's try to handle those cases if
|
532
|
+
# the Zstd gem is loaded.
|
533
|
+
#
|
534
|
+
# If you need to handle Zstd-encoded responses, install the 'zstd-ruby' gem and require it in your
|
535
|
+
# application. If the `Zstd` constant is defined, Mechanize will attempt to use it to inflate
|
536
|
+
# the response.
|
537
|
+
#
|
538
|
+
def content_encoding_zstd(body_io)
|
539
|
+
log.debug('deflate zstd body') if log
|
540
|
+
|
541
|
+
unless defined?(::Zstd)
|
542
|
+
raise Mechanize::Error, "cannot deflate zstd-encoded response. Please install and require the 'zstd-ruby' gem."
|
543
|
+
end
|
544
|
+
|
545
|
+
begin
|
546
|
+
return StringIO.new(Zstd.decompress(body_io.read))
|
547
|
+
rescue StandardError
|
548
|
+
log.error("unable to zstd#decompress response") if log
|
549
|
+
raise Mechanize::Error, "error decompressing zstd-encoded response."
|
550
|
+
end
|
551
|
+
ensure
|
552
|
+
body_io.close
|
553
|
+
end
|
554
|
+
|
526
555
|
def disable_keep_alive request
|
527
556
|
request['connection'] = 'close' unless @keep_alive
|
528
557
|
end
|
@@ -861,6 +890,8 @@ class Mechanize::HTTP::Agent
|
|
861
890
|
content_encoding_gunzip body_io
|
862
891
|
when 'br' then
|
863
892
|
content_encoding_brotli body_io
|
893
|
+
when 'zstd' then
|
894
|
+
content_encoding_zstd body_io
|
864
895
|
else
|
865
896
|
raise Mechanize::Error,
|
866
897
|
"unsupported content-encoding: #{response['Content-Encoding']}"
|
@@ -104,7 +104,7 @@ class Mechanize::PluggableParser
|
|
104
104
|
|
105
105
|
return parser if parser
|
106
106
|
|
107
|
-
mime_type = MIME::Type.new content_type
|
107
|
+
mime_type = MIME::Type.new "content-type" => content_type
|
108
108
|
|
109
109
|
parser = @parsers[mime_type.to_s] ||
|
110
110
|
@parsers[mime_type.simplified] ||
|
data/lib/mechanize/test_case.rb
CHANGED
@@ -15,11 +15,6 @@ end
|
|
15
15
|
|
16
16
|
require 'minitest/autorun'
|
17
17
|
|
18
|
-
begin
|
19
|
-
require 'minitest/pride'
|
20
|
-
rescue LoadError
|
21
|
-
end
|
22
|
-
|
23
18
|
##
|
24
19
|
# A generic test case for testing mechanize. Using a subclass of
|
25
20
|
# Mechanize::TestCase for your tests will create an isolated mechanize
|
data/lib/mechanize/version.rb
CHANGED
data/mechanize.gemspec
CHANGED
@@ -56,7 +56,7 @@ Gem::Specification.new do |spec|
|
|
56
56
|
spec.add_runtime_dependency("addressable", "~> 2.8")
|
57
57
|
spec.add_runtime_dependency("domain_name", ">= 0.5.20190701", "~> 0.5")
|
58
58
|
spec.add_runtime_dependency("http-cookie", ">= 1.0.3", "~> 1.0")
|
59
|
-
spec.add_runtime_dependency("mime-types", "~> 3.
|
59
|
+
spec.add_runtime_dependency("mime-types", "~> 3.3")
|
60
60
|
spec.add_runtime_dependency("net-http-digest_auth", ">= 1.4.1", "~> 1.4")
|
61
61
|
|
62
62
|
# careful! some folks are relying on older versions of net-http-persistent
|
@@ -2,7 +2,10 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'mechanize/test_case'
|
5
|
-
|
5
|
+
unless RUBY_PLATFORM == 'java'
|
6
|
+
require 'brotli'
|
7
|
+
require 'zstd-ruby'
|
8
|
+
end
|
6
9
|
|
7
10
|
class TestMechanizeHttpAgent < Mechanize::TestCase
|
8
11
|
|
@@ -965,6 +968,46 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
|
|
965
968
|
assert(body_io.closed?)
|
966
969
|
end
|
967
970
|
|
971
|
+
def test_response_content_encoding_zstd_when_zstd_not_loaded
|
972
|
+
skip("only test this on jruby which doesn't have zstd support") unless RUBY_ENGINE == 'jruby'
|
973
|
+
|
974
|
+
@res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
|
975
|
+
body_io = StringIO.new("content doesn't matter for this test")
|
976
|
+
|
977
|
+
e = assert_raises(Mechanize::Error) do
|
978
|
+
@agent.response_content_encoding(@res, body_io)
|
979
|
+
end
|
980
|
+
assert_includes(e.message, 'cannot deflate zstd-encoded response')
|
981
|
+
|
982
|
+
assert(body_io.closed?)
|
983
|
+
end
|
984
|
+
|
985
|
+
def test_response_content_encoding_zstd
|
986
|
+
skip('jruby does not have zstd support') if RUBY_ENGINE == 'jruby'
|
987
|
+
|
988
|
+
@res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
|
989
|
+
body_io = StringIO.new(Zstd.compress('this is compressed by zstd'))
|
990
|
+
|
991
|
+
body = @agent.response_content_encoding(@res, body_io)
|
992
|
+
|
993
|
+
assert_equal('this is compressed by zstd', body.read)
|
994
|
+
assert(body_io.closed?)
|
995
|
+
end
|
996
|
+
|
997
|
+
def test_response_content_encoding_zstd_corrupt
|
998
|
+
skip('jruby does not have zstd support') if RUBY_ENGINE == 'jruby'
|
999
|
+
|
1000
|
+
@res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
|
1001
|
+
body_io = StringIO.new('not a zstd payload')
|
1002
|
+
|
1003
|
+
e = assert_raises(Mechanize::Error) do
|
1004
|
+
@agent.response_content_encoding(@res, body_io)
|
1005
|
+
end
|
1006
|
+
assert_includes(e.message, 'error decompressing zstd-encoded response')
|
1007
|
+
assert_kind_of(RuntimeError, e.cause)
|
1008
|
+
assert(body_io.closed?)
|
1009
|
+
end
|
1010
|
+
|
968
1011
|
def test_response_content_encoding_gzip_corrupt
|
969
1012
|
log = StringIO.new
|
970
1013
|
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.12.
|
4
|
+
version: 2.12.2
|
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-
|
15
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: addressable
|
@@ -74,14 +74,14 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '3.
|
77
|
+
version: '3.3'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '3.
|
84
|
+
version: '3.3'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: net-http-digest_auth
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|