mechanize 2.12.0 → 2.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -1
- data/lib/mechanize/http/agent.rb +31 -0
- data/lib/mechanize/test_case.rb +0 -5
- data/lib/mechanize/version.rb +1 -1
- data/test/test_mechanize_http_agent.rb +44 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7183879e98b1195380219464368f7761a6ee2b9adb3eb18f47b216e740d840d5
|
4
|
+
data.tar.gz: 9eaf999bb67a5f7f7625b1a77a4466b88a005d947003b67e155398f3af2b0bf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba304c3a37d0eb98ccbbba83f425a68cb6ad2fb0da5d768a93cc8fd802f691da8fb86d7b6670888a597ca5f3f96ff755d6155197cbd1eef7c8db2442177bd72
|
7
|
+
data.tar.gz: db944be6db0079e9740c8e3aaade533baf990efbd87b6ebdbca034eb81a0adef82838fa50fd301f72d23c463109660a3256d0fae7f0154c8393a97b24ab214a1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Mechanize CHANGELOG
|
2
2
|
|
3
|
+
## 2.12.1 / 2024-08-21
|
4
|
+
|
5
|
+
* Introduce experimental support for handling Zstd-compressed responses (CRuby only). (#652) @adrianodennanni
|
6
|
+
|
7
|
+
|
3
8
|
## 2.12.0 / 2024-07-29
|
4
9
|
|
5
10
|
* 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']}"
|
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
@@ -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.1
|
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-08-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: addressable
|