Feature #6494

Send Accept-Encoding for all HTTP requests

Added by Eric Hodel almost 2 years ago. Updated over 1 year ago.

[ruby-core:45224]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:lib
Target version:2.0.0

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.

net.http.accept_gzip_deflate_by_default.patch Magnifier (3.31 KB) Eric Hodel, 05/25/2012 08:22 AM

net.http.accept_gzip_deflate_by_default.2.patch Magnifier (2.65 KB) Eric Hodel, 05/30/2012 08:55 AM

net.http.accept_gzip_deflate_by_default.3.patch Magnifier (4.31 KB) Eric Hodel, 06/09/2012 07:20 AM


Related issues

Blocked by ruby-trunk - Feature #6492: Inflate all HTTP Content-Encoding: deflate, gzip, x-gzip ... Closed 05/25/2012

Associated revisions

Revision 36473
Added by Eric Hodel over 1 year ago

  • 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/testhttprequest.rb: Tests for #6494
  • test/open-uri/testopen-uri.rb (testcontent_encoding): Updated test for automatic content-encoding handling.

Revision 36477
Added by Eric Hodel over 1 year ago

  • NEWS: Updated net/http for automatic proxy detection (#6546) and automatic gzip and deflate compression (#6492, #6494).

History

#1 Updated by Eric Hodel almost 2 years ago

Oops, forgot patch.

#2 Updated by Yui NARUSE almost 2 years ago

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 @responsehasbody 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

#3 Updated by Eric Hodel almost 2 years ago

Why remove the HAVEZLIB and @responsehas_body checks?

This updated patch incorporates your change to maintain backwards-compatibility but leaves in the HAVEZLIB and @responsehas_body checks.

#4 Updated by Yui NARUSE almost 2 years ago

drbrain (Eric Hodel) wrote:

Why remove the HAVEZLIB and @responsehas_body checks?

Ah, I wrongly removed it, it is needed.

This updated patch incorporates your change to maintain backwards-compatibility but leaves in the HAVEZLIB and @responsehas_body checks.

OK, you can commit it, thanks.

#5 Updated by Yusuke Endoh almost 2 years ago

  • Status changed from Open to Assigned
  • Assignee set to Yui NARUSE

#6 Updated by Yui NARUSE almost 2 years ago

  • Assignee changed from Yui NARUSE to Eric Hodel

#7 Updated by Eric Hodel almost 2 years ago

I will commit this once #6492 is approved and committed.

#8 Updated by Eric Hodel almost 2 years ago

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.

#9 Updated by Eric Hodel over 1 year ago

  • 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/testhttprequest.rb: Tests for #6494
  • test/open-uri/testopen-uri.rb (testcontent_encoding): Updated test for automatic content-encoding handling.

Also available in: Atom PDF