Feature #6494
closed
Send Accept-Encoding for all HTTP requests
Added by drbrain (Eric Hodel) over 12 years ago.
Updated over 12 years ago.
Description
This patch builds atop #6492 to enable Accept-Encoding by default for all HTTP requests that permit bodies. (Without #6492 it will break Net::HTTP.)
This patch moves setting the Accept-Encoding header from Net::HTTP#get to Net::HTTP::GenericRequest#initialize.
Files
This change breaks code which calls initialize with initheader=nil.
- def initialize(m, reqbody, resbody, path, initheader = nil)
- def initialize(m, reqbody, resbody, path, initheader = {})
Following
- if @response_has_body and Net::HTTP::HAVE_ZLIB then
-
unless initheader.keys.any? { |k| k.downcase == "accept-encoding" }
-
initheader = initheader.merge({
-
"accept-encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
-
})
-
end
- end
should be
-
if !initheader || !initheader.keys.any? { |k| k.downcase == "accept-encoding" }
-
initheader = initheader ? initheader.dup : {}
-
initheader["accept-encoding"] = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
-
end
Why remove the HAVE_ZLIB and @response_has_body checks?
This updated patch incorporates your change to maintain backwards-compatibility but leaves in the HAVE_ZLIB and @response_has_body checks.
drbrain (Eric Hodel) wrote:
Why remove the HAVE_ZLIB and @response_has_body checks?
Ah, I wrongly removed it, it is needed.
This updated patch incorporates your change to maintain backwards-compatibility but leaves in the HAVE_ZLIB and @response_has_body checks.
OK, you can commit it, thanks.
- Status changed from Open to Assigned
- Assignee set to naruse (Yui NARUSE)
- Assignee changed from naruse (Yui NARUSE) to drbrain (Eric Hodel)
I will commit this once #6492 is approved and committed.
Due to feedback from #6492 I have updated this patch to omit Accept-Encoding when Range is supplied in initheader.
I've also added documentation to this patch to describe the new compression behavior.
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r36473.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- 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.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0