* 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
@ -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>
|
Sat May 5 16:26:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/date/format.rb (Format::Bag#method_missing): get rid of
|
* lib/date/format.rb (Format::Bag#method_missing): get rid of
|
||||||
|
@ -461,7 +461,7 @@ module Net #:nodoc:
|
|||||||
@address = address
|
@address = address
|
||||||
@port = (port || HTTP.default_port)
|
@port = (port || HTTP.default_port)
|
||||||
@curr_http_version = HTTPVersion
|
@curr_http_version = HTTPVersion
|
||||||
@seems_1_0_server = false
|
@no_keepalive_server = false
|
||||||
@close_on_empty_response = false
|
@close_on_empty_response = false
|
||||||
@socket = nil
|
@socket = nil
|
||||||
@started = false
|
@started = false
|
||||||
@ -1062,12 +1062,7 @@ module Net #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def begin_transport(req)
|
def begin_transport(req)
|
||||||
if @socket.closed?
|
connect if @socket.closed?
|
||||||
connect
|
|
||||||
end
|
|
||||||
if @seems_1_0_server
|
|
||||||
req['connection'] ||= 'close'
|
|
||||||
end
|
|
||||||
if not req.response_body_permitted? and @close_on_empty_response
|
if not req.response_body_permitted? and @close_on_empty_response
|
||||||
req['connection'] ||= 'close'
|
req['connection'] ||= 'close'
|
||||||
end
|
end
|
||||||
@ -1076,15 +1071,13 @@ module Net #:nodoc:
|
|||||||
|
|
||||||
def end_transport(req, res)
|
def end_transport(req, res)
|
||||||
@curr_http_version = res.http_version
|
@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'
|
D 'Conn close'
|
||||||
@socket.close
|
@socket.close
|
||||||
elsif keep_alive?(req, res)
|
elsif keep_alive?(req, res)
|
||||||
D 'Conn keep-alive'
|
D 'Conn keep-alive'
|
||||||
if @socket.closed?
|
|
||||||
D 'Conn (but seems 1.0 server)'
|
|
||||||
@seems_1_0_server = true
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
D 'Conn close'
|
D 'Conn close'
|
||||||
@socket.close
|
@socket.close
|
||||||
@ -1092,13 +1085,12 @@ module Net #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def keep_alive?(req, res)
|
def keep_alive?(req, res)
|
||||||
return false if /close/i =~ req['connection'].to_s
|
return false if req.connection_close?
|
||||||
return false if @seems_1_0_server
|
if @curr_http_version <= '1.0'
|
||||||
return true if /keep-alive/i =~ res['connection'].to_s
|
res.connection_keep_alive?
|
||||||
return false if /close/i =~ res['connection'].to_s
|
else # HTTP/1.1 or later
|
||||||
return true if /keep-alive/i =~ res['proxy-connection'].to_s
|
not res.connection_close?
|
||||||
return false if /close/i =~ res['proxy-connection'].to_s
|
end
|
||||||
(@curr_http_version == '1.1')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sspi_auth?(res)
|
def sspi_auth?(res)
|
||||||
@ -1480,6 +1472,24 @@ module Net #:nodoc:
|
|||||||
end
|
end
|
||||||
private :basic_encode
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user