Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug #8182] XMLRPC request fails with "Wrong size. Was 31564, should be 1501" #308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions ChangeLog
@@ -1,3 +1,16 @@
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
Expand Down
8 changes: 6 additions & 2 deletions lib/net/http/response.rb
Expand Up @@ -254,7 +254,7 @@ def inflater # :nodoc:
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
Expand Down Expand Up @@ -344,8 +344,10 @@ class Inflater # :nodoc:
##
# 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
Expand All @@ -355,6 +357,7 @@ def initialize socket

def finish
@inflate.finish
@response['content-length'] = @deflated_len
end

##
Expand All @@ -367,6 +370,7 @@ def inflate_adapter(dest)
block = proc do |compressed_chunk|
@inflate.inflate(compressed_chunk) do |chunk|
dest << chunk
@deflated_len += chunk.bytesize
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/net/http/test_httpresponse.rb
Expand Up @@ -96,9 +96,11 @@ def test_read_body_content_encoding_deflate

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
Expand Down