aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-25 07:56:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-25 07:56:07 +0000
commite83922a3ce9c3cc65abe242f7756ffc31455c9a2 (patch)
tree863362dd992ff70577dbc80650ce8a3f5fa26b21 /lib
parent7a0f0e258b6dbeca3a9e357c22472cdd9f210b2b (diff)
downloadruby-e83922a3ce9c3cc65abe242f7756ffc31455c9a2.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http/header.rb20
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb
index 30cdb70b91..59980caef6 100644
--- a/lib/net/http/header.rb
+++ b/lib/net/http/header.rb
@@ -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