From e83922a3ce9c3cc65abe242f7756ffc31455c9a2 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 25 Apr 2016 07:56:07 +0000 Subject: 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 --- lib/net/http/header.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3