Project

General

Profile

Actions

Feature #6494

closed

Send Accept-Encoding for all HTTP requests

Added by drbrain (Eric Hodel) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
[ruby-core:45224]

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


Related issues 1 (0 open1 closed)

Blocked by Ruby master - Feature #6492: Inflate all HTTP Content-Encoding: deflate, gzip, x-gzip responses by defaultClosednaruse (Yui NARUSE)05/25/2012Actions

Updated by naruse (Yui NARUSE) over 12 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 @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
    

Updated by drbrain (Eric Hodel) over 12 years ago

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.

Updated by naruse (Yui NARUSE) over 12 years ago

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.

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to naruse (Yui NARUSE)

Updated by naruse (Yui NARUSE) over 12 years ago

  • Assignee changed from naruse (Yui NARUSE) to drbrain (Eric Hodel)

Updated by drbrain (Eric Hodel) over 12 years ago

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

Updated by drbrain (Eric Hodel) over 12 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.

Actions #9

Updated by drbrain (Eric Hodel) over 12 years 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/test_http_request.rb: Tests for #6494
  • test/open-uri/test_open-uri.rb (test_content_encoding): Updated test
    for automatic content-encoding handling.
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0