简体   繁体   English

Twisted Web客户端HTTP版本

[英]Twisted Web Client HTTP Version

If I am issuing an HTTP request using twisted.web.client.Agent how do I force the request to use HTTP 1.0? 如果我使用twisted.web.client.Agent发出HTTP请求,如何强制该请求使用HTTP 1.0? By default HTTP 1.1 is used. 默认情况下,使用HTTP 1.1。

Edit: The reason why I am interested in using HTTP 1.0 is because I wish to disable Chunked Transfer Encoding, and the most reliable way of doing this is by using HTTP 1.0. 编辑:我对使用HTTP 1.0感兴趣的原因是因为我希望禁用“块传输编码”,而最可靠的方法是使用HTTP 1.0。

If you want to use twisted.web.client.Agent , you can't without monkeypatching or something. 如果要使用twisted.web.client.Agent ,则不能没有monkeypatching之类的方法。 Tracing through the source , one of the things you'll find is: 通过源进行跟踪,您会发现其中之一:

# In the future, having the protocol version be a parameter to this
# method would probably be good.  It would be nice if this method
# weren't limited to issueing HTTP/1.1 requests.
requestLines = []
requestLines.append(
    '%s %s HTTP/1.1\r\n' % (self.method, self.uri))

So it's hardcoded. 因此它是硬编码的。 You might be able to get around that with some monkeypatching, but it's not terribly easy. 您可能可以通过一些猴子修补程序解决该问题,但这并不容易。


But that doesn't mean you're out of luck; 但是,这并不意味着您不走运。 that applies only to twisted.web.client.Agent . 仅适用于twisted.web.client.Agent If you can move away from using that class, it appears some old HTTP 1.0-only code is still around. 如果您可以放弃使用该类,那么似乎仍然有一些旧的仅HTTP 1.0的代码。 In particular, if you use these classes/functions, it looks like you'll be using HTTP 1.0: 特别是,如果您使用这些类/函数,则看起来将使用HTTP 1.0:

  • HTTPPageGetter
  • HTTPPageDownloader
  • HTTPClientFactory
  • HTTPDownloader
  • getPage
  • downloadPage

But if you stray from those, I think you'll end up using the new HTTP 1.1-only (for now) implementation. 但是,如果您背离了这些,我认为您最终将使用新的仅HTTP 1.1(目前)的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM