How can urllib2 / httplib talk HTTP 1.1 for HTTPS connections via a Squid proxy?

南楼画角 提交于 2019-12-11 02:25:14

问题


When I use urllib2 to make a HTTP 1.1 connection via a squid proxy, squid makes a new ongoing connection in HTTP 1.0.

How can I persuade Squid to talk 1.1 to the destination server?


回答1:


After dealing with this problem for an entire afternoon, i found the solution. So please excuse me answering my own question, but it would be great if someone else finds this useful and it saves them the pain.

In order to get Squid to have a HTTP 1.1 conversation with the destination server, the original request to it must be done via HTTP CONNECT. This is documented in the bug http://bugs.python.org/issue1424152.

There is a fix for py3k and it has been backported to Python 3.1 and 2.6.

If you are rocking a Python 2.5 or 2.4 installation, then you can download a patched version of httplib.py and urllib2.py here http://pypi.python.org/pypi/httpsproxy_urllib2. Simply replace your existing versions, or drop these 2 files into your project.



来源:https://stackoverflow.com/questions/1841730/how-can-urllib2-httplib-talk-http-1-1-for-https-connections-via-a-squid-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!