From: Ben Darnell Date: Sun, 27 Apr 2014 16:25:12 +0000 (-0400) Subject: Remove the has_body flag from write_headers. X-Git-Tag: v4.0.0b1~91^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61c05ab4921d2ec4ae5653cfba263c5b700a4be8;p=thirdparty%2Ftornado.git Remove the has_body flag from write_headers. It was only used client-side and we can infer whether we need to add a framing mechanism from the method instead. --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 22485f146..f23c76742 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -267,21 +267,19 @@ class HTTP1Connection(httputil.HTTPConnection): """ self._max_body_size = max_body_size - def write_headers(self, start_line, headers, chunk=None, callback=None, - has_body=True): + def write_headers(self, start_line, headers, chunk=None, callback=None): """Implements `.HTTPConnection.write_headers`.""" if self.is_client: self._request_start_line = start_line # Client requests with a non-empty body must have either a # Content-Length or a Transfer-Encoding. self._chunking_output = ( - has_body and + start_line.method in ('POST', 'PUT', 'PATCH') and 'Content-Length' not in headers and 'Transfer-Encoding' not in headers) else: self._response_start_line = start_line self._chunking_output = ( - has_body and # TODO: should this use # self._request_start_line.version or # start_line.version? diff --git a/tornado/httputil.py b/tornado/httputil.py index 23ef84b3e..17d6f1bb6 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -532,8 +532,7 @@ class HTTPConnection(object): .. versionadded:: 3.3 """ - def write_headers(self, start_line, headers, chunk=None, callback=None, - has_body=True): + def write_headers(self, start_line, headers, chunk=None, callback=None): """Write an HTTP header block. :arg start_line: a `.RequestStartLine` or `.ResponseStartLine`. @@ -542,9 +541,6 @@ class HTTPConnection(object): so that small responses can be written in the same call as their headers. :arg callback: a callback to be run when the write is complete. - :arg bool has_body: may be false to indicate that this message - has no body (and so does not need either a Content-Length - or Transfer-Encoding) Returns a `.Future` if no callback is given. """ diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 74580699f..ebab202b1 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -345,10 +345,7 @@ class _HTTPConnection(httputil.HTTPMessageDelegate): self._sockaddr) start_line = httputil.RequestStartLine(self.request.method, req_path, 'HTTP/1.1') - self.connection.write_headers( - start_line, self.request.headers, - has_body=(self.request.body is not None or - self.request.body_producer is not None)) + self.connection.write_headers(start_line, self.request.headers) if self.request.expect_100_continue: self._read_response() else: diff --git a/tornado/wsgi.py b/tornado/wsgi.py index e5bc9f96b..b9f8519a3 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -99,8 +99,7 @@ class _WSGIConnection(httputil.HTTPConnection): # so we can simply ignore the callback. pass - def write_headers(self, start_line, headers, chunk=None, callback=None, - has_body=True): + def write_headers(self, start_line, headers, chunk=None, callback=None): if self.method == 'HEAD': self._expected_content_remaining = 0 elif 'Content-Length' in headers: