From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS49981 109.236.80.0/20 X-Spam-Status: No, score=0.6 required=3.0 tests=BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,RDNS_NONE,SPF_FAIL,SPF_HELO_FAIL, TO_EQ_FM_DOM_SPF_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (unknown [109.236.90.209]) by dcvr.yhbt.net (Postfix) with ESMTP id 8DE442021F for ; Wed, 3 Aug 2016 02:57:17 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 1/3] response: drop clients after HTTP responses of unknown length Date: Wed, 3 Aug 2016 02:57:13 +0000 Message-Id: <20160803025715.31861-1-e@80x24.org> List-Id: 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