diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-01-09 20:23:16 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-01-09 20:23:16 (GMT) |
commit | 7e876f5e931b92e6becb08033a8980cb31fb2e8e (patch) | |
tree | f5f53583707500d2da3d9397a59a007559897b2e /Lib/httplib.py | |
parent | 3b2a6b819d93868c960da91aeebca7093d6f1627 (diff) | |
download | cpython-7e876f5e931b92e6becb08033a8980cb31fb2e8e.zip cpython-7e876f5e931b92e6becb08033a8980cb31fb2e8e.tar.gz cpython-7e876f5e931b92e6becb08033a8980cb31fb2e8e.tar.bz2 |
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/httplib.py')
-rw-r--r-- | Lib/httplib.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index fddfd9a..ba58e20 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -738,6 +738,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(("", "")) msg = "\r\n".join(self._buffer) @@ -745,9 +746,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, str): 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. @@ -927,12 +933,7 @@ class HTTPConnection: self._set_content_length(body) for hdr, value in headers.iteritems(): self.putheader(hdr, value) - if isinstance(body, str): - self.endheaders(body) - else: - self.endheaders() - if body: # when body is a file rather than a string - self.send(body) + self.endheaders(body) def getresponse(self): "Get the response from the server." |