views:

242

answers:

2

EDIT:

This question is invalid. Turns out a transparent proxy was making an onward HTTP 1.0 request even though urllib/httplib was indeed making a HTTP 1.1 request originally.

ORIGINAL QUESTION:

By default urllib2.urlopen always makes a HTTP 1.0 request.

Is there any way to get it to talk HTTP 1.1 ?

+7  A: 

Why do you think it's not already using http 1.1? Have you tried something like...:

>>> import urllib2
>>> urllib2._opener.handlers[1].set_http_debuglevel(100)
>>> urllib2.urlopen('http://mit.edu').read()[:10]
connect: (mit.edu, 80)
send: 'GET / HTTP/1.1

(etc, etc)? This should show it's sending a 1.1 GET request already.

Alex Martelli
A: 

urllib2 uses httplib to make HTTP requests. My Python 2.6.4 definitely uses HTTP/1.1 in httplib, although it can handle responses from a 1.1, 1.0 or 0.9 server. As far back as 2.3, this appears to be the case (and possibly back to 1.5)

However, if it is required to tunnel through a proxy, it will send a request like this:

CONNECT host:port HTTP/1.0

And that /1.0 string is hard-coded.

What version of python are you using, and how are you using urllib2?

Ian Clelland
I'm using 2.4 and 2.5. Please see this self-answered follow-up question for the solution to ongoing HTTP 1.1 via squid for HTTPS connections http://stackoverflow.com/questions/1841730/how-can-urllib2-httplib-make-http-1-1-for-https-connections-via-a-squid-proxy/1841740
Cheekysoft