Project

General

Profile

Bug #8182 » 308.patch

zzak (zzak _), 05/20/2013 07:37 AM

View differences:

ChangeLog
Thu May 16 18:09:03 2013 Duncan Mac-Vicar P. <dmacvicar@suse.de>
* lib/net/http/response.rb: transparently deflates the response body,
removes the "content-encoding" response header, but does not adjust
the "content-length" header accordingly.
So, pass the context to the Inflater so that we count the
uncompressed data for every chunk inflated, and then on finish we
set the right Content-Length.
[Bug #8182]
* test/net/http/test_httpresponse.rb: enhance testcase to check
the right Content-Length
Wed May 15 17:55:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_PLATFORM): move to config.h as needed by
lib/net/http/response.rb
when 'deflate', 'gzip', 'x-gzip' then
self.delete 'content-encoding'
inflate_body_io = Inflater.new(@socket)
inflate_body_io = Inflater.new(@socket, self)
begin
yield inflate_body_io
......
##
# Creates a new Inflater wrapping +socket+
def initialize socket
def initialize(socket, response)
@socket = socket
@response = response
@deflated_len = 0
# zlib with automatic gzip detection
@inflate = Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
end
......
def finish
@inflate.finish
@response['content-length'] = @deflated_len
end
##
......
block = proc do |compressed_chunk|
@inflate.inflate(compressed_chunk) do |chunk|
dest << chunk
@deflated_len += chunk.bytesize
end
end
test/net/http/test_httpresponse.rb
if Net::HTTP::HAVE_ZLIB
assert_equal nil, res['content-encoding']
assert_equal '5', res['content-length'], "Bug #8182"
assert_equal 'hello', body
else
assert_equal 'deflate', res['content-encoding']
assert_equal '13', res['content-length'], "Bug #8182"
assert_equal "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15", body
end
end
(1-1/3)