diff options
Diffstat (limited to 'test/net')
-rw-r--r-- | test/net/http/test_http.rb | 19 | ||||
-rw-r--r-- | test/net/http/test_http_request.rb | 22 | ||||
-rw-r--r-- | test/net/http/test_httpresponse.rb | 26 |
3 files changed, 67 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 280d08c321..32c8744413 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -419,6 +419,7 @@ module TestNetHTTP_version_1_2_methods def test_request start {|http| _test_request__GET http + _test_request__accept_encoding http _test_request__file http # _test_request__range http # WEBrick does not support Range: header. _test_request__HEAD http @@ -440,6 +441,24 @@ module TestNetHTTP_version_1_2_methods end assert_equal $test_net_http_data.size, res.body.size assert_equal $test_net_http_data, res.body + + assert res.decode_content, 'Bug #7831' + } + end + + def _test_request__accept_encoding(http) + req = Net::HTTP::Get.new('/', 'accept-encoding' => 'deflate') + http.request(req) {|res| + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + unless self.is_a?(TestNetHTTP_v1_2_chunked) + assert_not_nil res['content-length'] + assert_equal $test_net_http_data.size, res['content-length'].to_i + end + assert_equal $test_net_http_data.size, res.body.size + assert_equal $test_net_http_data, res.body + + refute res.decode_content, 'Bug #7831' } end diff --git a/test/net/http/test_http_request.rb b/test/net/http/test_http_request.rb index c01e52c0b4..4ce93acde3 100644 --- a/test/net/http/test_http_request.rb +++ b/test/net/http/test_http_request.rb @@ -53,5 +53,27 @@ class HTTPRequestTest < Test::Unit::TestCase assert_equal expected, req.to_hash end + def test_initialize_accept_encoding + req1 = Net::HTTP::Get.new '/' + + assert req1.decode_content, 'Bug #7831 - automatically decode content' + + req2 = Net::HTTP::Get.new '/', 'accept-encoding' => 'identity' + + refute req2.decode_content, + 'Bug #7381 - do not decode content if the user overrides' + end + + def test_header_set + req = Net::HTTP::Get.new '/' + + assert req.decode_content, 'Bug #7831 - automatically decode content' + + req['accept-encoding'] = 'identity' + + refute req.decode_content, + 'Bug #7831 - do not decode content if the user overrides' + end + end diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb index 121b81fe96..974f8296cc 100644 --- a/test/net/http/test_httpresponse.rb +++ b/test/net/http/test_httpresponse.rb @@ -86,6 +86,7 @@ x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15 EOS res = Net::HTTPResponse.read_new(io) + res.decode_content = true body = nil @@ -118,6 +119,7 @@ x\x9C\xCBH\xCD\xC9 EOS res = Net::HTTPResponse.read_new(io) + res.decode_content = true body = nil @@ -134,6 +136,29 @@ EOS end end + def test_read_body_content_encoding_deflate_disabled + io = dummy_io(<<EOS) +HTTP/1.1 200 OK +Connection: close +Content-Encoding: deflate +Content-Length: 13 + +x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15 +EOS + + res = Net::HTTPResponse.read_new(io) + res.decode_content = false # user set accept-encoding in request + + body = nil + + res.reading_body io, true do + body = res.read_body + end + + assert_equal 'deflate', res['content-encoding'], 'Bug #7831' + assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body, 'Bug #7381' + end + def test_read_body_content_encoding_deflate_no_length io = dummy_io(<<EOS) HTTP/1.1 200 OK @@ -144,6 +169,7 @@ x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15 EOS res = Net::HTTPResponse.read_new(io) + res.decode_content = true body = nil |