【问题标题】:Python 3.3 HTTPConnection endheaders and send dataPython 3.3 HTTPConnection 端头和发送数据
【发布时间】:2013-03-30 00:12:06
【问题描述】:

Python 3.3/Lib/urllib/request.py 下,AbstractHTTPHandler(BaseHandler) 类中,第 1252

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

HTTPConnection 类中的Python 3.3/Lib/http/client.py 下,在以下几行中:

第 1047 行

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

第 1068 行

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

第 1087 行

self.endheaders(正文)

urllib.request.urlopen(req, data)http.client.HTTPConnection中调用request(method, url, body=None, headers={})时,body和req.data会对应相同的字符串或其他数据。

这是否意味着以下两个相同? (他们在文档中似乎不一样)

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

我完全糊涂了。

【问题讨论】:

    标签: python send httpconnection


    【解决方案1】:

    endheaders 在内部(间接)使用send。差异可能在于性能。如果data 是一个字节对象,那么.endheaders(data) 会尝试将标头和数据一起发送。见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.
    

    【讨论】:

    • 啊.. 非常感谢!这是非常及时和有帮助的。
    猜你喜欢
    • 1970-01-01
    • 2014-05-23
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2012-01-06
    • 2019-09-05
    相关资源
    最近更新 更多