about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-08-03 02:57:13 +0000
committerEric Wong <e@80x24.org>2016-08-03 02:57:33 +0000
commitbc4db45073e1a5b143e0aacb5767cec868b60201 (patch)
tree2371e71ce63a131545d229827cbbdaf961824411 /lib
parente8bf70aea2e13df5ea7282aeb417e034c16d0d41 (diff)
downloadyahns-bc4db45073e1a5b143e0aacb5767cec868b60201.tar.gz
Clients are not able to handle persistent connections unless
the client knows the length of the response.
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/http_response.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index 88ff9f9..f2d9c62 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -126,6 +126,7 @@ module Yahns::HttpResponse # :nodoc:
     k = self.class
     alive = @hs.next? && k.persistent_connections
     flags = MSG_DONTWAIT
+    term = false
 
     if @hs.headers?
       code = status.to_i
@@ -147,14 +148,19 @@ 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
+          term = true
           flags |= MSG_MORE if value.to_i > 0 && !hdr_only
           kv_str(buf, key, value)
+        when %r{\ATransfer-Encoding\z}i
+          term = true if value =~ /\bchunked\b/i
+          kv_str(buf, key, value)
         when "rack.hijack"
           hijack = value
         else
           kv_str(buf, key, value)
         end
       end
+      alive &&= term
       buf << (alive ? "Connection: keep-alive\r\n\r\n".freeze
                     : "Connection: close\r\n\r\n".freeze)
       case rv = kgio_syssend(buf, flags)