0

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.

veered
  • 628
  • 8
  • 19
  • Why the downvote? I searched the docs, web, and source code pretty thoroughly and I was not able to find an answer. – veered Dec 07 '14 at 23:26
  • HTTP 1.1 was released in 1999. At the time, Netscape Navigator 4.0 was a current web browser. Do you really need to support Netscape Navigator 3.0? – Glyph Dec 08 '14 at 00:46
  • @Glyph No, I want to turn off Chunked Transfer Encoding, and the most reliable way of doing this is by using HTTP 1.0. And it is not like *nothing* uses HTTP 1.0 anymore, see [this post](http://stackoverflow.com/questions/2073392/is-http-1-0-still-in-use) for instance. – veered Dec 08 '14 at 18:36
  • But point taken, I will modify the original question to include this justification. – veered Dec 08 '14 at 18:49

1 Answers1

1

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.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • I don't think that twisted.web.client.Agent uses HTTPClient. And even if it does, if you look at the server logs then a GET request from Agent gives you something like GET index.html HTTP/1.1. So it is definitely using HTTP 1.1 by default. Also by default twisted.web.http.protocol_version is "HTTP/1.1" (on line 129 of the source you linked to). – veered Dec 07 '14 at 23:44
  • @Veered: Sorry, you must be looking at the old version of my answer. I looked into it further and indeed, Twisted has two separate implementations of HTTP clients, one older HTTP 1.0 implementation and a new HTTP 1.1 implementation. I think `Agent` will always use the 1.1 implementation, so if you want 1.0, you might have to use some of the older functions and classes. (Also, that `protocol_version = "HTTP/1.1"` is a red herring, since that variable is never used.) – icktoofay Dec 07 '14 at 23:48
  • Oh gotcha, thanks for the update! Since this is for personal use right now I just stuck with Agent and manually changed the source you linked to, and it works great! – veered Dec 08 '14 at 00:05