yahns Ruby server user/dev discussion
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 1/4] response: drop clients after HTTP responses of unknown length
Date: Wed,  3 Aug 2016 03:19:03 +0000
Message-ID: <20160803031906.14553-2-e@80x24.org> (raw)
In-Reply-To: <20160803031906.14553-1-e@80x24.org>

Clients are not able to handle persistent connections unless
the client knows the length of the response.
---
 lib/yahns/http_response.rb   | 6 ++++++
 test/test_extras_exec_cgi.rb | 4 +---
 2 files changed, 7 insertions(+), 3 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 @@ def http_response_write(status, headers, body, hdr_only)
     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 @@ def http_response_write(status, headers, body, hdr_only)
           # 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)
diff --git a/test/test_extras_exec_cgi.rb b/test/test_extras_exec_cgi.rb
index f9b96d9..3c71fd4 100644
--- a/test/test_extras_exec_cgi.rb
+++ b/test/test_extras_exec_cgi.rb
@@ -169,10 +169,8 @@ def _blocked_zombie(block_on, rtype)
         assert_match %r{200 OK}, head
         assert_match %r{\A\d+\n\z}, body
         exec_pid = body.to_i
-        assert_raises(Errno::EAGAIN, IO::WaitReadable) { c.read_nonblock(666) }
         poke_until_dead exec_pid
-        # still alive?
-        assert_raises(Errno::EAGAIN, IO::WaitReadable) { c.read_nonblock(666) }
+        assert_raises(EOFError) { c.read_nonblock(666) }
       else
         raise "BUG in test, bad rtype"
       end
-- 
EW


  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-03  3:19 [PATCH 0/4] remove chunked/Content-Length requirement from apps Eric Wong
2016-08-03  3:19 ` Eric Wong [this message]
2016-08-03  3:19 ` [PATCH 2/4] response: reduce stack overhead for parameter passing Eric Wong
2016-08-03  3:19 ` [PATCH 3/4] response: support auto-chunking for HTTP/1.1 Eric Wong
2016-08-03  3:19 ` [PATCH 4/4] Revert "document Rack::Chunked/ContentLength semi-requirements" Eric Wong

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160803031906.14553-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git