Bug #11268 ยป net_http.patch
lib/net/http/generic_request.rb | ||
---|---|---|
@decode_content = true
|
||
initheader = initheader ? initheader.dup : {}
|
||
initheader["accept-encoding"] =
|
||
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
||
"gzip;q=1.0,identity;q=0.3"
|
||
end
|
||
end
|
||
... | ... | |
end
|
||
end
|
||
lib/net/http/response.rb | ||
---|---|---|
v = self['content-encoding']
|
||
case v && v.downcase
|
||
when 'deflate', 'gzip', 'x-gzip' then
|
||
when 'gzip', 'x-gzip' then
|
||
self.delete 'content-encoding'
|
||
inflate_body_io = Inflater.new(@socket)
|
||
... | ... | |
end
|
||
end
|
||
test/net/http/test_http_request.rb | ||
---|---|---|
'user-agent' => %w[Ruby],
|
||
}
|
||
expected['accept-encoding'] = %w[gzip;q=1.0,deflate;q=0.6,identity;q=0.3] if
|
||
expected['accept-encoding'] = %w[gzip;q=1.0,identity;q=0.3] if
|
||
Net::HTTP::HAVE_ZLIB
|
||
assert_equal expected, req.to_hash
|
||
... | ... | |
end if Net::HTTP::HAVE_ZLIB
|
||
end
|
||
test/net/http/test_httpresponse.rb | ||
---|---|---|
assert_equal 'hello', body
|
||
end
|
||
def test_read_body_content_encoding_deflate
|
||
def test_read_body_content_encoding_gzip
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
Content-Length: 13
|
||
Content-Encoding: gzip
|
||
Content-Length: 25
|
||
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
|
||
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
... | ... | |
assert_equal nil, res['content-encoding']
|
||
assert_equal 'hello', body
|
||
else
|
||
assert_equal 'deflate', res['content-encoding']
|
||
assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
|
||
assert_equal 'gzib', res['content-encoding']
|
||
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
|
||
end
|
||
end
|
||
def test_read_body_content_encoding_deflate_uppercase
|
||
def test_read_body_content_encoding_gzip_uppercase
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: DEFLATE
|
||
Content-Length: 13
|
||
Content-Encoding: GZIP
|
||
Content-Length: 25
|
||
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
|
||
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
... | ... | |
assert_equal nil, res['content-encoding']
|
||
assert_equal 'hello', body
|
||
else
|
||
assert_equal 'DEFLATE', res['content-encoding']
|
||
assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
|
||
assert_equal 'GZIP', res['content-encoding']
|
||
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
|
||
end
|
||
end
|
||
def test_read_body_content_encoding_deflate_chunked
|
||
def test_read_body_content_encoding_gzip_chunked
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
Content-Encoding: gzip
|
||
Transfer-Encoding: chunked
|
||
6
|
||
x\x9C\xCBH\xCD\xC9
|
||
7
|
||
\xC9\a\x00\x06,\x02\x15
|
||
d
|
||
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD
|
||
c
|
||
\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
|
||
0
|
||
EOS
|
||
... | ... | |
assert_equal nil, res['content-encoding']
|
||
assert_equal 'hello', body
|
||
else
|
||
assert_equal 'deflate', res['content-encoding']
|
||
assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
|
||
assert_equal 'gzip', res['content-encoding']
|
||
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
|
||
end
|
||
end
|
||
def test_read_body_content_encoding_deflate_disabled
|
||
def test_read_body_content_encoding_gzip_disabled
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
Content-Length: 13
|
||
Content-Encoding: gzip
|
||
Content-Length: 25
|
||
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
|
||
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
... | ... | |
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'
|
||
assert_equal 'gzip', res['content-encoding']
|
||
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
|
||
end
|
||
def test_read_body_content_encoding_deflate_no_length
|
||
def test_read_body_content_encoding_gzip_no_length
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
Content-Encoding: gzip
|
||
x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15
|
||
\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
... | ... | |
assert_equal nil, res['content-encoding']
|
||
assert_equal 'hello', body
|
||
else
|
||
assert_equal 'deflate', res['content-encoding']
|
||
assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15\r\n", body
|
||
assert_equal 'gzip', res['content-encoding']
|
||
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00", body
|
||
end
|
||
end
|
||