From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 2/2] proxy_pass: do not chunk on bodyless upstream responses
Date: Wed, 14 Dec 2016 06:59:52 +0000 [thread overview]
Message-ID: <20161214065952.28950-3-e@80x24.org> (raw)
In-Reply-To: <20161214065952.28950-1-e@80x24.org>
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.
---
lib/yahns/proxy_http_response.rb | 2 +-
test/test_proxy_pass.rb | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 74f5ce5..1776291 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -120,7 +120,7 @@ def proxy_res_headers(res, req_res)
# chunk the response ourselves if the client supports it,
# but the backend does not terminate properly
- if alive && ! term
+ if alive && ! term && have_body
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
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 @@ def chunky.each
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 @@ def test_proxy_pass
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 @@ def check_forbidden_put(host, port)
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
--
EW
prev parent reply other threads:[~2016-12-14 6:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-14 6:59 [PATCH 0/2] revenge of the body-less responses Eric Wong
2016-12-14 6:59 ` [PATCH 1/2] response: do not set chunked header on bodyless responses Eric Wong
2016-12-14 6:59 ` Eric Wong [this message]
Reply instructions:
You may reply publicly 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=20161214065952.28950-3-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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).