From df92940cc9afdd8a95301734c2c79471ed861c9a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 8 Apr 2015 06:09:40 +0000 Subject: proxy_pass: support backends which rely on EOF to terminate Not all backends are capable of generating chunked responses (especially not to HTTP/1.0 clients) nor can they generate the Content-Length (especially when gzipping), so they'll close the socket to signal EOF instead. --- test/test_proxy_pass.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/test_proxy_pass.rb') diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb index e4e97d1..eb866b3 100644 --- a/test/test_proxy_pass.rb +++ b/test/test_proxy_pass.rb @@ -65,6 +65,16 @@ class TestProxyPass < Testcase io = env['rack.hijack'].call io.write(TRUNCATE_BODY) io.close + when '/eof-body-fast' + io = env['rack.hijack'].call + io.write("HTTP/1.0 200 OK\r\n\r\neof-body-fast") + io.close + when '/eof-body-slow' + io = env['rack.hijack'].call + io.write("HTTP/1.0 200 OK\r\n\r\n") + sleep 0.1 + io.write("eof-body-slow") + io.close when '/truncate-head' io = env['rack.hijack'].call io.write(TRUNCATE_HEAD) @@ -244,6 +254,7 @@ class TestProxyPass < Testcase end end + check_eof_body(host, port) check_pipelining(host, port) check_response_trailer(host, port) @@ -531,4 +542,22 @@ class TestProxyPass < Testcase end thrs.each { |t| assert_equal(:OK, t.value) } end + + def check_eof_body(host, port) + Timeout.timeout(60) do + s = TCPSocket.new(host, port) + s.write("GET /eof-body-fast HTTP/1.0\r\n\r\n") + res = s.read + assert_match %r{\AHTTP/1\.1 200 OK\r\n}, res + assert_match %r{\r\n\r\neof-body-fast\z}, res + s.close + + s = TCPSocket.new(host, port) + s.write("GET /eof-body-slow HTTP/1.0\r\n\r\n") + res = s.read + assert_match %r{\AHTTP/1\.1 200 OK\r\n}, res + assert_match %r{\r\n\r\neof-body-slow\z}, res + s.close + end + end end -- cgit v1.2.3-24-ge0c7