From: Ben Darnell Date: Tue, 1 Jan 2019 17:50:07 +0000 (-0500) Subject: http1connection: Fix a bug with redirects and chunked requests X-Git-Tag: v6.0.0b1~7^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f486a4aec746e9d66441600ee3b0743228b061c;p=thirdparty%2Ftornado.git http1connection: Fix a bug with redirects and chunked requests After a redirect, the chunked-encoding header is already set and would not be detected correctly. This affects empty bodies with allow_nonstandard_methods and any use of body_producer. --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 30f2a172e..fd63be627 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -390,7 +390,10 @@ class HTTP1Connection(httputil.HTTPConnection): self._chunking_output = ( start_line.method in ("POST", "PUT", "PATCH") and "Content-Length" not in headers - and "Transfer-Encoding" not in headers + and ( + "Transfer-Encoding" not in headers + or headers["Transfer-Encoding"] == "chunked" + ) ) else: assert isinstance(start_line, httputil.ResponseStartLine) diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 29319c743..9adbcea46 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -307,6 +307,21 @@ Transfer-Encoding: chunked # don't either). self.assertEqual(301, response.code) + def test_redirect_put_with_body(self): + response = self.fetch( + "/redirect?url=/put&status=307", method="PUT", body="hello" + ) + self.assertEqual(response.body, b"Put body: hello") + + def test_redirect_put_without_body(self): + # This "without body" edge case is similar to what happens with body_producer. + response = self.fetch( + "/redirect?url=/put&status=307", + method="PUT", + allow_nonstandard_methods=True, + ) + self.assertEqual(response.body, b"Put body: ") + def test_credentials_in_url(self): url = self.get_url("/auth").replace("http://", "http://me:secret@") response = self.fetch(url)