From: Sebastien Boving Date: Tue, 27 Jun 2017 16:35:55 +0000 (-0700) Subject: Do not send/expect Content-Length on 1xx X-Git-Tag: v5.0.0~66^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38e9b6ca705228fea4049b885931216dea2cca70;p=thirdparty%2Ftornado.git Do not send/expect Content-Length on 1xx --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 618af0b30..ec05b7b52 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -350,10 +350,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, diff --git a/tornado/web.py b/tornado/web.py index 33346516f..c86d9838d 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -997,7 +997,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)