diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-07 10:02:52 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-07 10:02:52 -0800 |
commit | b788a0f1eedfb358f9d57f40cec6ba0960dea3fe (patch) | |
tree | d58b3631827dc9ebe8998c0c5ee2d3c1532998dd | |
parent | 370fb8c7811704ed65384f599b52ac1b6d0c36c9 (diff) | |
download | rainbows-b788a0f1eedfb358f9d57f40cec6ba0960dea3fe.tar.gz |
Reading headers is common and we don't want to create new String objects (even if they're tiny or copy-on-write) for the GC to munch on.
-rw-r--r-- | lib/rainbows/ev_core.rb | 8 | ||||
-rw-r--r-- | lib/rainbows/response.rb | 3 |
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 23505d3..a9fc41e 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -18,8 +18,8 @@ module Rainbows::EvCore # "Transfer-Encoding: chunked", and the async.callback stuff # isn't Rack::Lint-compatible, so we have to enforce it here. headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers - alive = headers.include?("Content-Length") || - !!(%r{\Achunked\z}i =~ headers["Transfer-Encoding"]) + alive = headers.include?(Content_Length) || + !!(%r{\Achunked\z}i =~ headers[Transfer_Encoding]) end write_response(status, headers, body, alive) end @@ -50,10 +50,10 @@ module Rainbows::EvCore # returns whether to enable response chunking for autochunk models def stream_response_headers(status, headers, alive) headers = Rack::Utils::HeaderHash.new(headers) - if headers['Content-Length'] + if headers[Content_Length] rv = false else - rv = !!(headers['Transfer-Encoding'] =~ %r{\Achunked\z}i) + rv = !!(headers[Transfer_Encoding] =~ %r{\Achunked\z}i) rv = false if headers.delete('X-Rainbows-Autochunk') == 'no' end write_headers(status, headers, alive) diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index 4992696..111813f 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -4,6 +4,8 @@ module Rainbows::Response include Unicorn::HttpResponse Close = "close" KeepAlive = "keep-alive" + Content_Length = "Content-Length".freeze + Transfer_Encoding = "Transfer-Encoding".freeze # private file class for IO objects opened by Rainbows! itself (and not # the app or middleware) @@ -112,7 +114,6 @@ module Rainbows::Response if IO.method_defined?(:sendfile_nonblock) || IO.respond_to?(:copy_stream) HTTP_RANGE = 'HTTP_RANGE' Content_Range = 'Content-Range'.freeze - Content_Length = 'Content-Length'.freeze # This does not support multipart responses (does anybody actually # use those?) |