Twisted Web Client HTTP Version

544 Views Asked by At

If I am issuing an HTTP request using twisted.web.client.Agent how do I force the request to use HTTP 1.0? By default HTTP 1.1 is used.

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.

1

There are 1 best solutions below

3
On BEST ANSWER

If you want to use twisted.web.client.Agent, you can’t without monkeypatching or something. 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. If you can move away from using that class, it appears some old HTTP 1.0-only code is still around. In particular, if you use these classes/functions, it looks like you’ll be using 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.