ruby-changes:42688
From: nobu <ko1@a...>
Date: Mon, 25 Apr 2016 15:59:31 +0900 (JST)
Subject: [ruby-changes:42688] nobu:r54762 (trunk): net/http/header.rb: refactor
nobu 2016-04-25 16:56:07 +0900 (Mon, 25 Apr 2016) New Revision: 54762 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54762 Log: 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. Modified files: trunk/lib/net/http/header.rb Index: lib/net/http/header.rb =================================================================== --- lib/net/http/header.rb (revision 54761) +++ lib/net/http/header.rb (revision 54762) @@ -436,21 +436,17 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L436 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/