diff options
author | Eric Wong <e@80x24.org> | 2014-02-04 21:34:29 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2014-02-04 21:34:29 +0000 |
commit | 913714b848e2e41876c96a60fe9913197005625b (patch) | |
tree | 5dd5791993c7e60f052268074050a8568f4412f0 /lib | |
parent | 6673121b8ec74976950bba4df3f5b9fc13ef1649 (diff) | |
download | yahns-913714b848e2e41876c96a60fe9913197005625b.tar.gz |
We must not cork response headers when the response body is empty, otherwise those headers will be delayed by 200ms.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/yahns/http_response.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index e257feb..8965fd0 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -31,6 +31,8 @@ module Yahns::HttpResponse # :nodoc: R100_RAW = "HTTP/1.1 100 Continue\r\n\r\n" R100_CCC = "100 Continue\r\n\r\nHTTP/1.1 " HTTP_EXPECT = "HTTP_EXPECT" + REQUEST_METHOD = "REQUEST_METHOD" + HEAD = "HEAD" # no point in using one without the other, these have been in Linux # for ages @@ -123,6 +125,10 @@ module Yahns::HttpResponse # :nodoc: end end + def have_more?(value) + value.to_i > 0 && @hs.env[REQUEST_METHOD] != HEAD + end + # writes the rack_response to socket as an HTTP response # returns :wait_readable, :wait_writable, :forget, or nil def http_response_write(status, headers, body) @@ -149,7 +155,7 @@ module Yahns::HttpResponse # :nodoc: # allow Rack apps to tell us they want to drop the client alive = false if value =~ /\bclose\b/i when %r{\AContent-Length\z}i - flags |= MSG_MORE + flags |= MSG_MORE if have_more?(value) buf << kv_str(key, value) when "rack.hijack" hijack = value |