问题描述
当我使用urllib2通过squid代理建立HTTP 1.1连接时,squid在HTTP 1.0中建立了一个新的持续连接。
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.
我如何说服Squid谈话1.1到目标服务器?
How can I persuade Squid to talk 1.1 to the destination server?
推荐答案
在整个下午处理这个问题之后,我找到了解决方案。所以请原谅我回答我自己的问题,但是如果其他人发现这个问题很有用就会很好,这会让他们免于痛苦。
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.
为了让Squid得到一个HTTP 1.1与目标服务器的对话,对它的原始请求必须通过HTTP CONNECT完成。这在的错误中有记录。
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.
py3k有一个修复程序,它已被反向移植到Python 3.1和2.6。
There is a fix for py3k and it has been backported to Python 3.1 and 2.6.
如果你正在使用Python 2.5或2.4安装,然后你可以在这里下载修补版本的httplib.py和urllib2.py 。只需替换现有版本,或将这两个文件放入项目中。
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.
这篇关于urllib2 / httplib如何通过Squid代理与HTTP连接进行HTTP 1.1连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!