Question

Under Python 3.3/Lib/urllib/request.py, in class AbstractHTTPHandler(BaseHandler), at line 1252

h.request(req.get_method(), req.selector, req.data, headers)

Under Python 3.3/Lib/http/client.py in class HTTPConnection, in the following lines:

Line 1047

def request(self, method, url, body=None, headers={}):

Line 1068

def _send_request(self, method, url, body, headers):

Line 1087

self.endheaders(body)

Above the body and req.data would correspond to the same string or other data, when urllib.request.urlopen(req, data) calls request(method, url, body=None, headers={}) in http.client.HTTPConnection.

Does this mean that the following two are the same? (They don't seem to be the same in the doc)

  1. HTTPConnection.endheaders(data)
  2. HTTPConnection.endheaders(), HTTPConnection.send(data)

I am totally confused.

Was it helpful?

Solution

endheaders uses send internally (indirectly). The difference might be in performance. If data is a bytes object then .endheaders(data) tries to send headers and data together. See the comment in _send_output():

896         # If msg and message_body are sent in a single send() call,
897         # it will avoid performance problems caused by the interaction
898         # between delayed ack and the Nagle algorithm.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top