mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
net/http/header.rb: refactor
* lib/net/http/header.rb (connection_close?): match headers without making intermediate arrays. * lib/net/http/header.rb (connection_keep_alive?): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7a0f0e258b
commit
e83922a3ce
1 changed files with 8 additions and 12 deletions
|
@ -436,21 +436,17 @@ module Net::HTTPHeader
|
|||
private :basic_encode
|
||||
|
||||
def connection_close?
|
||||
tokens(@header['connection']).include?('close') or
|
||||
tokens(@header['proxy-connection']).include?('close')
|
||||
token = /(?:\A|,)\s*close\s*(?:\z|,)/i
|
||||
@header['connection']&.grep(token) {return true}
|
||||
@header['proxy-connection']&.grep(token) {return true}
|
||||
false
|
||||
end
|
||||
|
||||
def connection_keep_alive?
|
||||
tokens(@header['connection']).include?('keep-alive') or
|
||||
tokens(@header['proxy-connection']).include?('keep-alive')
|
||||
token = /(?:\A|,)\s*keep-alive\s*(?:\z|,)/i
|
||||
@header['connection']&.grep(token) {return true}
|
||||
@header['proxy-connection']&.grep(token) {return true}
|
||||
false
|
||||
end
|
||||
|
||||
def tokens(vals)
|
||||
return [] unless vals
|
||||
vals.map {|v| v.split(',') }.flatten\
|
||||
.reject {|str| str.strip.empty? }\
|
||||
.map {|tok| tok.strip.downcase }
|
||||
end
|
||||
private :tokens
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue