diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-02-05 14:30:29 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-02-09 19:50:41 -0800 |
commit | cda1f3381096cdb8c78a126a4993e458bf798ca2 (patch) | |
tree | 2cab13e70c2e7b72d87dc35a5b2b2ef7e92c0683 | |
parent | bf680b1a61ab17b6a0e17432fd4ab22358ec83bd (diff) | |
download | unicorn-cda1f3381096cdb8c78a126a4993e458bf798ca2.tar.gz |
Regenerating headers constantly is a waste of time.
-rw-r--r-- | lib/unicorn/const.rb | 8 | ||||
-rw-r--r-- | lib/unicorn/http_response.rb | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/unicorn/const.rb b/lib/unicorn/const.rb index 8cefd2b..b44bb29 100644 --- a/lib/unicorn/const.rb +++ b/lib/unicorn/const.rb @@ -44,6 +44,12 @@ module Unicorn 505 => 'HTTP Version not supported' } + HTTP_STATUS_HEADERS = HTTP_STATUS_CODES.inject({}) do |hash, (code, text)| + text.freeze + hash[code] = "HTTP/1.1 #{code} #{text}\r\nConnection: close\r\n".freeze + hash + end + # Frequently used constants when constructing requests or responses. Many times # the constant just refers to a string with the same contents. Using these constants # gave about a 3% to 10% performance improvement over using the strings directly. @@ -91,7 +97,6 @@ module Unicorn MAX_BODY=MAX_HEADER # A frozen format for this is about 15% faster - STATUS_FORMAT = "HTTP/1.1 %d %s\r\nConnection: close\r\n".freeze CONTENT_TYPE = "Content-Type".freeze LAST_MODIFIED = "Last-Modified".freeze ETAG = "ETag".freeze @@ -109,4 +114,5 @@ module Unicorn REDIRECT = "HTTP/1.1 302 Found\r\nLocation: %s\r\nConnection: close\r\n\r\n".freeze HOST = "HOST".freeze end + end diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index c3094cf..7454516 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -87,7 +87,7 @@ module Unicorn def send_status(content_length=@body.length) if not @status_sent @header['Content-Length'] = content_length if content_length and @status != 304 - write(Const::STATUS_FORMAT % [@status, HTTP_STATUS_CODES[@status]]) + write(HTTP_STATUS_HEADERS[@status]) @status_sent = true end end |