mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 17:43:59 +02:00
* lib/net/http: Do not handle Content-Encoding when the user sets Accept-Encoding. This allows users to handle Content-Encoding for themselves. This restores backwards-compatibility with Ruby 1.x. * lib/net/http/generic_request.rb: ditto. * lib/net/http/response.rb: ditto * test/net/http/test_http.rb: Test for the above. * test/net/http/test_http_request.rb: ditto. * test/net/http/test_httpresponse.rb: ditto. [ruby-trunk - Bug #7831] * lib/net/http.rb: Removed OpenSSL dependency from Net::HTTP. * test/net/http/test_http.rb: Remove Zlib dependency from tests. * test/net/http/test_http_request.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aea2c7ca50
commit
ddddf044b2
8 changed files with 117 additions and 3 deletions
|
@ -27,11 +27,14 @@ class Net::HTTPGenericRequest
|
|||
raise ArgumentError, "HTTP request path is empty" if path.empty?
|
||||
@path = path
|
||||
|
||||
@decode_content = false
|
||||
|
||||
if @response_has_body and Net::HTTP::HAVE_ZLIB then
|
||||
if !initheader ||
|
||||
!initheader.keys.any? { |k|
|
||||
%w[accept-encoding range].include? k.downcase
|
||||
} then
|
||||
@decode_content = true
|
||||
initheader = initheader ? initheader.dup : {}
|
||||
initheader["accept-encoding"] =
|
||||
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
||||
|
@ -51,10 +54,25 @@ class Net::HTTPGenericRequest
|
|||
attr_reader :path
|
||||
attr_reader :uri
|
||||
|
||||
# Automatically set to false if the user sets the Accept-Encoding header.
|
||||
# This indicates they wish to handle Content-encoding in responses
|
||||
# themselves.
|
||||
attr_reader :decode_content
|
||||
|
||||
def inspect
|
||||
"\#<#{self.class} #{@method}>"
|
||||
end
|
||||
|
||||
##
|
||||
# Don't automatically decode response content-encoding if the user indicates
|
||||
# they want to handle it.
|
||||
|
||||
def []=(key, val) # :nodoc:
|
||||
@decode_content = false if key.downcase == 'accept-encoding'
|
||||
|
||||
super key, val
|
||||
end
|
||||
|
||||
def request_body_permitted?
|
||||
@request_has_body
|
||||
end
|
||||
|
@ -291,6 +309,7 @@ class Net::HTTPGenericRequest
|
|||
if IO.select([sock.io], nil, nil, sock.continue_timeout)
|
||||
res = Net::HTTPResponse.read_new(sock)
|
||||
unless res.kind_of?(Net::HTTPContinue)
|
||||
res.decode_content = @decode_content
|
||||
throw :response, res
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,6 +80,7 @@ class Net::HTTPResponse
|
|||
@body = nil
|
||||
@read = false
|
||||
@uri = nil
|
||||
@decode_content = false
|
||||
end
|
||||
|
||||
# The HTTP version supported by the server.
|
||||
|
@ -98,6 +99,10 @@ class Net::HTTPResponse
|
|||
# if a URI was used to create the request.
|
||||
attr_reader :uri
|
||||
|
||||
# Set to true automatically when the request did not contain an
|
||||
# Accept-Encoding header from the user.
|
||||
attr_accessor :decode_content
|
||||
|
||||
def inspect
|
||||
"#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
|
||||
end
|
||||
|
@ -242,6 +247,7 @@ class Net::HTTPResponse
|
|||
|
||||
def inflater # :nodoc:
|
||||
return yield @socket unless Net::HTTP::HAVE_ZLIB
|
||||
return yield @socket unless @decode_content
|
||||
return yield @socket if self['content-range']
|
||||
|
||||
case self['content-encoding']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue