yahns Ruby server user/dev discussion
 help / color / Atom feed
* [PATCH] proxy_pass: do not chunk HTTP/1.0 with keep-alive
@ 2016-05-16  1:12 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-05-16  1:12 UTC (permalink / raw)
  To: yahns-public

Instead, we must drop non-terminated responses since
HTTP/1.0 clients do not understand chunked encoding.

This is necessary for "ab -k" which still uses HTTP/1.0.
---
 lib/yahns/proxy_http_response.rb |  8 ++++++--
 test/test_proxy_pass.rb          | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index c5e7be5..bd274fe 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -105,8 +105,12 @@ def proxy_response_start(res, tip, kcar, req_res)
 
     # chunk the response ourselves if the client supports it,
     # but the backend does not terminate properly
-    if alive && ! term && (env['HTTP_VERSION'] == 'HTTP/1.1'.freeze)
-      res << "Transfer-Encoding: chunked\r\n".freeze
+    if alive && ! term
+      if env['HTTP_VERSION'] == 'HTTP/1.1'.freeze
+        res << "Transfer-Encoding: chunked\r\n".freeze
+      else # we can't persist HTTP/1.0 and HTTP/0.9 w/o Content-Length
+        alive = false
+      end
     end
     res << (alive ? "Connection: keep-alive\r\n\r\n".freeze
                   : "Connection: close\r\n\r\n".freeze)
diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb
index c938976..5dd8058 100644
--- a/test/test_proxy_pass.rb
+++ b/test/test_proxy_pass.rb
@@ -572,6 +572,16 @@ def check_response_trailer(host, port)
   end
 
   def check_eof_body(host, port)
+    Timeout.timeout(30) do
+      s = TCPSocket.new(host, port)
+      s.write("GET /eof-body-fast HTTP/1.0\r\nConnection:keep-alive\r\n\r\n")
+      res = s.read
+      assert_match %r{\AHTTP/1\.[01] 200 OK\r\n}, res
+      assert_match %r{\r\nConnection: close\r\n}, res
+      assert_match %r{\r\n\r\neof-body-fast\z}, res
+      s.close
+    end
+
     Timeout.timeout(60) do
       s = TCPSocket.new(host, port)
       s.write("GET /eof-body-fast HTTP/1.0\r\n\r\n")

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-16  1:12 [PATCH] proxy_pass: do not chunk HTTP/1.0 with keep-alive Eric Wong

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