真的很简单的Python HTTP代理吗?
我到处都找过,发现了数以百万计的Python代理服务器,但没有一个完全符合我的要求(我认为:s)
我对Python有相当多的经验,但我对黑暗的世界还很陌生HTTP 协议的秘密。
我认为可能有用的是一个非常简单的代理示例,可以连接到它,然后它本身会尝试连接到传递给它的地址。
另外,我认为让我感到困惑的是隐藏的东西正在做的一切,例如,如果该类继承自 BaseHTTPServer.BaseHTTPRequestHandler 请求页面时到底会发生什么,就像在我发现的许多示例中没有对路径的引用一样变则突然噗! self.path 在函数中使用。我假设它已被继承,但它最终如何得到所使用的路径?
如果这没有多大意义,我很抱歉,因为我对我的问题的想法可能是混乱的:(
如果你能想到任何能让我的问题更清楚的东西,请建议我添加它。xxx
编辑:
另外,链接到解释代理处理请求、请求页面(此时如何读取/修改数据)并将其传递给原始请求者的详细过程将不胜感激 xxxx
I have looked everywhere and found millions of python proxy servers but none do precisely what i would like (i think :s)
I have had quite a bit of experience with python generally, but i'm quite new to the world of the deep dark secrets of the HTTP protocol.
What i think might be useful would be a very simple proxy example that can be connected to and will then itself try to connect to the address passed to it.
Also, i think what has been confusing me is everything the hidden stuff is doing, e.g. if the class inherits from BaseHTTPServer.BaseHTTPRequestHandler what precisely happens when a page is requested, as in many of the examples i have found there is no reference to path variable then suddenly poof! self.path is used in a function. im assuming it's been inherited, but how does it end up with the path used?
im sorry if that didn't make much sense, as my idea of my problem is probably scrambled :(
if you can think of anything which would make my question clearer please, please suggest i add it. xxx
Edit:
Also, a link to an explaination of the detailed processes through which the proxy handles the request, requests the page (how to read/modify the data at this point) and passes it to the original requester would be greatly appreciated xxxx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“一个非常简单的代理示例,可以连接到,然后它本身会尝试连接到传递给它的地址。”这实际上就是 HTTP 代理的定义。
这里有一个非常简单的代理示例:SimpleHTTPServer 模块。
它的核心只有 3 行:
所以它是一个
SimpleHTTPRequestHandler
,响应 GET 请求,打开路径中的 URL(对代理的请求通常类似于“GET http://example.com/",不像“GET /index.html”)。然后,它只是将从该 URL 读取到的所有内容复制到响应中。请注意,这确实是最小的。我相信它根本不处理标题。
顺便说一句:
path
记录在 http://docs.python.org /library/basehttpserver.html。它是在调用do*
方法之前设置的。"a very simple proxy example that can be connected to and will then itself try to connect to the address passed to it." That is practically the definition of an HTTP proxy.
There's a really simple proxy example here: The SimpleHTTPServer module.
The core of it is just 3 lines:
So it's a
SimpleHTTPRequestHandler
that, in response to a GET request, opens the URL in the path (a request to a proxy typically looks like "GET http://example.com/", not like "GET /index.html"). It then just copies whatever it can read from that URL to the response.Notet that this is really minimal. It doesn't deal with headers at all, I believe.
BTW:
path
is documented at http://docs.python.org/library/basehttpserver.html. It was set before yourdo*
method was called.来自 扭曲 Wiki
From the twisted Wiki
proxpy 看起来很有前途,调整请求和响应非常简单。
proxpy looks rather promising, it's very simple to tweak requests and responses.