mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/net/http.rb: Connection header field might include both of "keep-alive" token and "close" token. [ruby-core:10818]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
84daaed844
commit
094d3b1d7c
2 changed files with 34 additions and 19 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun May 6 17:54:36 2007 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* lib/net/http.rb: Connection header field might include both of
|
||||
"keep-alive" token and "close" token. [ruby-core:10818]
|
||||
|
||||
Sat May 5 16:26:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/date/format.rb (Format::Bag#method_missing): get rid of
|
||||
|
|
|
@ -461,7 +461,7 @@ module Net #:nodoc:
|
|||
@address = address
|
||||
@port = (port || HTTP.default_port)
|
||||
@curr_http_version = HTTPVersion
|
||||
@seems_1_0_server = false
|
||||
@no_keepalive_server = false
|
||||
@close_on_empty_response = false
|
||||
@socket = nil
|
||||
@started = false
|
||||
|
@ -1062,12 +1062,7 @@ module Net #:nodoc:
|
|||
end
|
||||
|
||||
def begin_transport(req)
|
||||
if @socket.closed?
|
||||
connect
|
||||
end
|
||||
if @seems_1_0_server
|
||||
req['connection'] ||= 'close'
|
||||
end
|
||||
connect if @socket.closed?
|
||||
if not req.response_body_permitted? and @close_on_empty_response
|
||||
req['connection'] ||= 'close'
|
||||
end
|
||||
|
@ -1076,15 +1071,13 @@ module Net #:nodoc:
|
|||
|
||||
def end_transport(req, res)
|
||||
@curr_http_version = res.http_version
|
||||
if not res.body and @close_on_empty_response
|
||||
if @socket.closed?
|
||||
D 'Conn socket closed'
|
||||
elsif not res.body and @close_on_empty_response
|
||||
D 'Conn close'
|
||||
@socket.close
|
||||
elsif keep_alive?(req, res)
|
||||
D 'Conn keep-alive'
|
||||
if @socket.closed?
|
||||
D 'Conn (but seems 1.0 server)'
|
||||
@seems_1_0_server = true
|
||||
end
|
||||
else
|
||||
D 'Conn close'
|
||||
@socket.close
|
||||
|
@ -1092,13 +1085,12 @@ module Net #:nodoc:
|
|||
end
|
||||
|
||||
def keep_alive?(req, res)
|
||||
return false if /close/i =~ req['connection'].to_s
|
||||
return false if @seems_1_0_server
|
||||
return true if /keep-alive/i =~ res['connection'].to_s
|
||||
return false if /close/i =~ res['connection'].to_s
|
||||
return true if /keep-alive/i =~ res['proxy-connection'].to_s
|
||||
return false if /close/i =~ res['proxy-connection'].to_s
|
||||
(@curr_http_version == '1.1')
|
||||
return false if req.connection_close?
|
||||
if @curr_http_version <= '1.0'
|
||||
res.connection_keep_alive?
|
||||
else # HTTP/1.1 or later
|
||||
not res.connection_close?
|
||||
end
|
||||
end
|
||||
|
||||
def sspi_auth?(res)
|
||||
|
@ -1480,6 +1472,24 @@ module Net #:nodoc:
|
|||
end
|
||||
private :basic_encode
|
||||
|
||||
def connection_close?
|
||||
tokens(@header['connection']).include?('close') or
|
||||
tokens(@header['proxy-connection']).include?('close')
|
||||
end
|
||||
|
||||
def connection_keep_alive?
|
||||
tokens(@header['connection']).include?('keep-alive') or
|
||||
tokens(@header['proxy-connection']).include?('keep-alive')
|
||||
end
|
||||
|
||||
def tokens(vals)
|
||||
return [] unless vals
|
||||
vals.map {|v| v.split(',') }.flatten\
|
||||
.reject {|str| str.strip.empty? }\
|
||||
.map {|tok| tok.downcase }
|
||||
end
|
||||
private :tokens
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue