diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-19 22:43:38 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-19 22:43:38 +0000 |
commit | b1a0509b5465ce77f52e0384159237889a8d60ec (patch) | |
tree | ea22ccb90a2367364e0c740f15ad571558b025f4 /lib/net/http.rb | |
parent | ef19dcf96dd2e84c4fe0a46888a5afd0cd457f80 (diff) |
* lib/net/http/response.rb: Automatically inflate gzip and
deflate-encoded response bodies. [Feature #6942]
* lib/net/http/generic_request.rb: Automatically accept gzip and
deflate content-encoding for requests. [Feature #6494]
* lib/net/http/request.rb: Updated documentation for #6494.
* lib/net/http.rb: Updated documentation for #6492 and #6494, removed
Content-Encoding handling now present in Net::HTTPResponse.
* test/net/http/test_httpresponse.rb: Tests for #6492
* test/net/http/test_http_request.rb: Tests for #6494
* test/open-uri/test_open-uri.rb (test_content_encoding): Updated test
for automatic content-encoding handling.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r-- | lib/net/http.rb | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index 7efea79cdd..977daabe1c 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -283,6 +283,14 @@ module Net #:nodoc: # See Net::HTTP::Proxy for further details and examples such as proxies that # require a username and password. # + # === Compression + # + # Net::HTTP automatically adds Accept-Encoding for compression of response + # bodies and automatically decompresses gzip and deflate responses unless a + # Range header was sent. + # + # Compression can be disabled through the Accept-Encoding: identity header. + # # == HTTP Request Classes # # Here is the HTTP request class hierarchy. @@ -602,7 +610,6 @@ module Net #:nodoc: @use_ssl = false @ssl_context = nil @enable_post_connection_check = true - @compression = nil @sspi_enabled = false SSL_IVNAMES.each do |ivname| instance_variable_set ivname, nil @@ -1052,28 +1059,10 @@ module Net #:nodoc: initheader = initheader.merge({ "accept-encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" }) - @compression = true end end request(Get.new(path, initheader)) {|r| - if r.key?("content-encoding") and @compression - @compression = nil # Clear it till next set. - the_body = r.read_body dest, &block - case r["content-encoding"] - when "gzip" - r.body= Zlib::GzipReader.new(StringIO.new(the_body), encoding: "ASCII-8BIT").read - r.delete("content-encoding") - when "deflate" - r.body= Zlib::Inflate.inflate(the_body); - r.delete("content-encoding") - when "identity" - ; # nothing needed - else - ; # Don't do anything dramatic, unless we need to later - end - else - r.read_body dest, &block - end + r.read_body dest, &block res = r } res |