mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
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.
This commit is contained in:
parent
3b2a6b819d
commit
7e876f5e93
1 changed files with 8 additions and 7 deletions
|
@ -738,6 +738,7 @@ class HTTPConnection:
|
||||||
"""Send the currently buffered request and clear the buffer.
|
"""Send the currently buffered request and clear the buffer.
|
||||||
|
|
||||||
Appends an extra \\r\\n to 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(("", ""))
|
self._buffer.extend(("", ""))
|
||||||
msg = "\r\n".join(self._buffer)
|
msg = "\r\n".join(self._buffer)
|
||||||
|
@ -745,9 +746,14 @@ class HTTPConnection:
|
||||||
# If msg and message_body are sent in a single send() call,
|
# If msg and message_body are sent in a single send() call,
|
||||||
# it will avoid performance problems caused by the interaction
|
# it will avoid performance problems caused by the interaction
|
||||||
# between delayed ack and the Nagle algorithim.
|
# between delayed ack and the Nagle algorithim.
|
||||||
if message_body is not None:
|
if isinstance(message_body, str):
|
||||||
msg += message_body
|
msg += message_body
|
||||||
|
message_body = None
|
||||||
self.send(msg)
|
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):
|
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
|
||||||
"""Send a request to the server.
|
"""Send a request to the server.
|
||||||
|
@ -927,12 +933,7 @@ class HTTPConnection:
|
||||||
self._set_content_length(body)
|
self._set_content_length(body)
|
||||||
for hdr, value in headers.iteritems():
|
for hdr, value in headers.iteritems():
|
||||||
self.putheader(hdr, value)
|
self.putheader(hdr, value)
|
||||||
if isinstance(body, str):
|
self.endheaders(body)
|
||||||
self.endheaders(body)
|
|
||||||
else:
|
|
||||||
self.endheaders()
|
|
||||||
if body: # when body is a file rather than a string
|
|
||||||
self.send(body)
|
|
||||||
|
|
||||||
def getresponse(self):
|
def getresponse(self):
|
||||||
"Get the response from the server."
|
"Get the response from the server."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue