"""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)
# 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.
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."""