Skip to content

Commit

Permalink
Remove the has_body flag from write_headers.
Browse files Browse the repository at this point in the history
It was only used client-side and we can infer whether we need to add
a framing mechanism from the method instead.
  • Loading branch information
bdarnell committed Apr 27, 2014
1 parent 8630b3b commit 61c05ab
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
6 changes: 2 additions & 4 deletions tornado/http1connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,19 @@ def set_max_body_size(self, max_body_size):
"""
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?
Expand Down
6 changes: 1 addition & 5 deletions tornado/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -542,9 +541,6 @@ def write_headers(self, start_line, headers, chunk=None, callback=None,
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.
"""
Expand Down
5 changes: 1 addition & 4 deletions tornado/simple_httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ def _on_connect(self):
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:
Expand Down
3 changes: 1 addition & 2 deletions tornado/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def set_close_callback(self, callback):
# 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:
Expand Down

0 comments on commit 61c05ab

Please sign in to comment.