diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-08-18 13:57:29 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-08-18 14:01:20 -0700 |
commit | dc28a812b3fe369e1adfd3b8f30574469a988bef (patch) | |
tree | a9356ac1cd6e39ae19271767ed4c03488dee1f6f | |
parent | 637d59209bef0eeb2643aadfa4c44a01ca905bd9 (diff) | |
download | unicorn-dc28a812b3fe369e1adfd3b8f30574469a988bef.tar.gz |
The overhead of the temporary array is too little to be worth worrying about...
-rw-r--r-- | lib/unicorn/http_response.rb | 9 |
1 files 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 |