Bug #11058 » 0002-lib-net-http-response.rb-Net-HTTPResponse-Inflater.patch
lib/net/http/response.rb | ||
---|---|---|
@socket = socket
|
||
# zlib with automatic gzip detection
|
||
@inflate = Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
|
||
@bytes_read = 0
|
||
end
|
||
##
|
||
# Finishes the inflate stream.
|
||
def finish
|
||
return if @bytes_read == 0
|
||
@inflate.finish
|
||
end
|
||
... | ... | |
dest.force_encoding(Encoding::ASCII_8BIT)
|
||
end
|
||
block = proc do |compressed_chunk|
|
||
@bytes_read += compressed_chunk.bytesize
|
||
@inflate.inflate(compressed_chunk) do |chunk|
|
||
dest << chunk
|
||
end
|
test/net/http/test_httpresponse.rb | ||
---|---|---|
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03", body
|
||
end
|
||
def test_read_body_content_encoding_deflate_empty_body
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
Content-Length: 0
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
res.decode_content = true
|
||
body = nil
|
||
res.reading_body io, true do
|
||
body = res.read_body
|
||
end
|
||
if Net::HTTP::HAVE_ZLIB
|
||
assert_equal nil, res['content-encoding']
|
||
assert_equal '', body
|
||
else
|
||
assert_equal 'deflate', res['content-encoding']
|
||
assert_equal '', body
|
||
end
|
||
end
|
||
def test_read_body_content_encoding_deflate_empty_body_no_length
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
||
Connection: close
|
||
Content-Encoding: deflate
|
||
EOS
|
||
res = Net::HTTPResponse.read_new(io)
|
||
res.decode_content = true
|
||
body = nil
|
||
res.reading_body io, true do
|
||
body = res.read_body
|
||
end
|
||
if Net::HTTP::HAVE_ZLIB
|
||
assert_equal nil, res['content-encoding']
|
||
assert_equal '', body
|
||
else
|
||
assert_equal 'deflate', res['content-encoding']
|
||
assert_equal '', body
|
||
end
|
||
end
|
||
def test_read_body_string
|
||
io = dummy_io(<<EOS)
|
||
HTTP/1.1 200 OK
|
- « Previous
- 1
- 2
- Next »