From f1d90f71b04d128a102b4207e05f5fb9b141b669 Mon Sep 17 00:00:00 2001 From: Bulat Khasanov Date: Sun, 8 Sep 2019 18:06:55 +0300 Subject: [PATCH] Omit Transfer-Encoding header for HEAD response --- tornado/http1connection.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 5fd37ab86..9e71e594c 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -406,6 +406,8 @@ class HTTP1Connection(httputil.HTTPConnection): # self._request_start_line.version or # start_line.version? self._request_start_line.version == "HTTP/1.1" + # Omit payload header field for HEAD request. + and self._request_start_line.method != "HEAD" # 1xx, 204 and 304 responses have no body (not even a zero-length # body), and so should not have either Content-Length or # Transfer-Encoding headers. @@ -511,10 +513,7 @@ class HTTP1Connection(httputil.HTTPConnection): % self._expected_content_remaining ) if self._chunking_output: - assert self._request_start_line - if not self.stream.closed() and ( - self.is_client or self._request_start_line.method != "HEAD" - ): + if not self.stream.closed(): self._pending_write = self.stream.write(b"0\r\n\r\n") self._pending_write.add_done_callback(self._on_write_complete) self._write_finished = True -- 2.47.2