Cheekysoft
Cheekysoft

Reputation: 35590

Can urllib2 make HTTP/1.1 requests?

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 ?

Upvotes: 3

Views: 4161

Answers (2)

Ian Clelland
Ian Clelland

Reputation: 44152

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?

Upvotes: 3

Alex Martelli
Alex Martelli

Reputation: 882103

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.

Upvotes: 12

Related Questions