diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-03-01 13:48:06 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-04-02 02:49:21 +0900 |
commit | 58adb1636be32fb95173f01e448673dbae4511b0 (patch) | |
tree | 3d360132f7dda85e289539acd0137235d81cb68b /lib | |
parent | 651b832c1b574df1c6095c49d77cccf0f250aa7f (diff) | |
download | ruby-58adb1636be32fb95173f01e448673dbae4511b0.tar.gz |
[ruby/net-http] Update the content-length heading when decoding bodies
Previously, the content-encoding header was removed and the body
was modified, but the content-length header was not modified,
resulting in the content-length header not matching the body
length.
Fixes [Bug #16672]
https://github.com/ruby/net-http/commit/a7cb30124c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/http/response.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index 08eaeb2cac..cbe16ca205 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -263,6 +263,7 @@ class Net::HTTPResponse case v&.downcase when 'deflate', 'gzip', 'x-gzip' then self.delete 'content-encoding' + had_content_length = self.delete 'content-length' inflate_body_io = Inflater.new(@socket) @@ -272,6 +273,9 @@ class Net::HTTPResponse ensure begin inflate_body_io.finish + if had_content_length + self['content-length'] = inflate_body_io.bytes_inflated.to_s + end rescue => err # Ignore #finish's error if there is an exception from yield raise err if success @@ -374,6 +378,14 @@ class Net::HTTPResponse end ## + # The number of bytes inflated, used to update the Content-Length of + # the response. + + def bytes_inflated + @inflate.total_out + end + + ## # Returns a Net::ReadAdapter that inflates each read chunk into +dest+. # # This allows a large response body to be inflated without storing the |