From dc28a812b3fe369e1adfd3b8f30574469a988bef Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 18 Aug 2009 13:57:29 -0700 Subject: http_response: allow reentrancy The overhead of the temporary array is too little to be worth worrying about... --- lib/unicorn/http_response.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index 5602a43..114243c 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -31,22 +31,21 @@ module Unicorn # Connection: and Date: headers no matter what (if anything) our # Rack application sent us. SKIP = { 'connection' => true, 'date' => true, 'status' => true }.freeze - OUT = [] # :nodoc # writes the rack_response to socket as an HTTP response def self.write(socket, rack_response) status, headers, body = rack_response status = CODES[status.to_i] || status - OUT.clear + tmp = [] # Don't bother enforcing duplicate supression, it's a Hash most of # the time anyways so just hope our app knows what it's doing headers.each do |key, value| next if SKIP.include?(key.downcase) if value =~ /\n/ - value.split(/\n/).each { |v| OUT << "#{key}: #{v}\r\n" } + value.split(/\n/).each { |v| tmp << "#{key}: #{v}\r\n" } else - OUT << "#{key}: #{value}\r\n" + tmp << "#{key}: #{value}\r\n" end end @@ -58,7 +57,7 @@ module Unicorn "Date: #{Time.now.httpdate}\r\n" \ "Status: #{status}\r\n" \ "Connection: close\r\n" \ - "#{OUT.join(Z)}\r\n") + "#{tmp.join(Z)}\r\n") body.each { |chunk| socket.write(chunk) } socket.close # flushes and uncorks the socket immediately ensure -- cgit v1.2.3-24-ge0c7