diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-01-18 00:04:57 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-01-18 00:04:57 (GMT) |
commit | 822b21c43b137137bc84774ae47d118a4628b6b3 (patch) | |
tree | 98a505e5ae6fab5445db769cefcb39ef31f35f32 /Lib/http | |
parent | b4ddfa41cc320902ba2ea6949ec76d2097c71b71 (diff) | |
download | cpython-822b21c43b137137bc84774ae47d118a4628b6b3.zip cpython-822b21c43b137137bc84774ae47d118a4628b6b3.tar.gz cpython-822b21c43b137137bc84774ae47d118a4628b6b3.tar.bz2 |
Merged revisions 68458 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68458 | kristjan.jonsson | 2009-01-09 14:23:16 -0600 (Fri, 09 Jan 2009) | 1 line
Issue 4336: HTTPRequest._send_output() now deals with the case of the message body not being a string. This allows clients to use endheaders(message_body) instead of endheaders() + send(message_body) without making any extra checks.
........
Diffstat (limited to 'Lib/http')
-rw-r--r-- | Lib/http/client.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index 34bf6a9..d2900b1 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -697,6 +697,7 @@ class HTTPConnection: """Send the currently buffered request and clear the buffer. Appends an extra \\r\\n to the buffer. + A message_body may be specified, to be appended to the request. """ self._buffer.extend((b"", b"")) msg = b"\r\n".join(self._buffer) @@ -704,9 +705,14 @@ class HTTPConnection: # If msg and message_body are sent in a single send() call, # it will avoid performance problems caused by the interaction # between delayed ack and the Nagle algorithim. - if message_body is not None: + if isinstance(message_body, bytes): msg += message_body + message_body = None self.send(msg) + if message_body is not None: + #message_body was not a string (i.e. it is a file) and + #we must run the risk of Nagle + self.send(message_body) def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0): """Send a request to the server. @@ -894,12 +900,7 @@ class HTTPConnection: self._set_content_length(body) for hdr, value in headers.items(): self.putheader(hdr, value) - if isinstance(body, str): - self.endheaders(body.encode('ascii')) - else: - self.endheaders() - if body: # when body is a file rather than a string - self.send(body) + self.endheaders(body.encode('ascii') if isinstance(body, str) else body) def getresponse(self): """Get the response from the server.""" |