From 1a1499d67d7b1b8525b2a73478cb3588e132b731 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 14 Dec 2016 06:59:52 +0000 Subject: proxy_pass: do not chunk on bodyless upstream responses As with the previous commit ("response: do not set chunked header on bodyless responses"), blindly setting "Transfer-Encoding: chunked" is wrong and confuses "curl -T" on 204 responses, at least. --- test/test_proxy_pass.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/test_proxy_pass.rb') diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb index 4c4b53a..22f1802 100644 --- a/test/test_proxy_pass.rb +++ b/test/test_proxy_pass.rb @@ -154,6 +154,9 @@ class TestProxyPass < Testcase env['rack.hijack'].call.close # should not be seen: [ 123, [ %w(Content-Type text/html), %w(Content-Length 0) ], [] ] + when '/204' + buf = env['rack.input'].read # drain + [ 204, {}, [] ] else buf = env['rack.input'].read [ 201, { @@ -271,6 +274,7 @@ class TestProxyPass < Testcase end end + check_204_on_put(host, port) check_forbidden_put(host, port) check_eof_body(host, port) check_pipelining(host, port) @@ -639,4 +643,33 @@ class TestProxyPass < Testcase ensure to_close.each(&:close) end + + def check_204_on_put(host, port) + s = TCPSocket.new(host, port) + s.write("PUT /204 HTTP/1.1\r\nHost: example.com\r\n" \ + "Content-Length: 11\r\n" \ + "Content-Type: application/octet-stream\r\n" \ + "\r\nhello worldPUT") + buf = s.readpartial(1024) + assert_match %r{\AHTTP/1\.1 204}, buf + assert_match %r{\r\n\r\n\z}, buf + refute_match %r{^Transfer-Encoding}i, buf + refute_match %r{^Content-Length}i, buf + assert_match %r{^Connection: keep-alive\r\n}, buf + assert_nil IO.select([s], nil, nil, 1), 'connection persists..' + + # make sure another on the same connection works + s.write(" / HTTP/1.1\r\nHost: example.com\r\n" \ + "Content-Length: 11\r\n" \ + "Content-Type: application/octet-stream\r\n" \ + "\r\nhello world") + buf = s.readpartial(1024) + assert_match %r{\r\n\r\nhello world\z}, buf + assert_match %r{\AHTTP/1\.1 201}, buf + assert_match(%r{^Content-Length: 11\r\n}, buf) + assert_match %r{^Connection: keep-alive\r\n}, buf + assert_nil IO.select([s], nil, nil, 1), 'connection persists..' + ensure + s.close if s + end end -- cgit v1.2.3-24-ge0c7