]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Do not send/expect Content-Length on 1xx
authorSebastien Boving <seb@google.com>
Tue, 27 Jun 2017 16:35:55 +0000 (09:35 -0700)
committerBen Darnell <ben@bendarnell.com>
Fri, 5 Jan 2018 03:10:28 +0000 (22:10 -0500)
tornado/http1connection.py
tornado/web.py

index 53744ece39481d153e06411f3aa7edf380e3cd5c..20d98e437d71154cf58d7d98f1defbda4d9f357e 100644 (file)
@@ -349,10 +349,11 @@ class HTTP1Connection(httputil.HTTPConnection):
                 # self._request_start_line.version or
                 # start_line.version?
                 self._request_start_line.version == 'HTTP/1.1' and
-                # 304 responses have no body (not even a zero-length body), and so
-                # should not have either Content-Length or Transfer-Encoding.
-                # headers.
+                # 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.
                 start_line.code not in (204, 304) and
+                (start_line.code < 100 or start_line.code >= 200) and
                 # No need to chunk the output if a Content-Length is specified.
                 'Content-Length' not in headers and
                 # Applications are discouraged from touching Transfer-Encoding,
index d79889fa3768df9daaa3eb18ad8de068735068a3..338fe0f050beeebdf1941c2b547d00c8737d7b54 100644 (file)
@@ -977,7 +977,8 @@ class RequestHandler(object):
             if self._status_code in (204, 304):
                 assert not self._write_buffer, "Cannot send body with %s" % self._status_code
                 self._clear_headers_for_304()
-            elif "Content-Length" not in self._headers:
+            elif ("Content-Length" not in self._headers and
+                  (self._status_code < 100 or self._status_code >= 200)):
                 content_length = sum(len(part) for part in self._write_buffer)
                 self.set_header("Content-Length", content_length)