如何用Python编写代理服务器?

发布于 2024-07-23 09:50:26 字数 119 浏览 3 评论 0原文

我想编写一个程序来更改 Web 浏览器发送的请求中的 HTTP 标头。 我相信这可以通过代理服务器来完成。 所以,我想写一个代理服务器。

我是学编程的。 我怎样才能在Python中做到这一点?

I want to write a program that changes the HTTP headers in my requests that are sent by my web-browser. I believe it can be done with a proxy server. So, I'd like to write a proxy server.

I study programming. How can I do this in Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

浅浅 2024-07-30 09:50:26

下面的例子很好地说明了如何在没有框架开销的情况下做到这一点。

http://www.warriorhut.org/whatwg/websocket-proxy.py

Good example below on how to do this without the overhead of a framework.

http://www.warriorhut.org/whatwg/websocket-proxy.py

晨曦慕雪 2024-07-30 09:50:26

查看Twisted 框架,特别是扭曲网络。 它在 MIT 下都是免费提供的,因此您可以构建和/或修改它。

另请参阅 Python Twisted 示例

Look at the Twisted framework, particularly Twisted Web. It's all freely available under MIT, so you can build off and/or modify it.

See also Python Twisted Examples.

作死小能手 2024-07-30 09:50:26

虽然 Twisted 正如 @Matthew 推荐的那样非常棒,但更容易学习、理解和修改可能是 这个小例子——与 Twisted 可以提供的“生产质量”和可扩展性相去甚远,但是,您可以从它开始来更好地理解问题。

对于用 Python 编写的各种开源 HTTP 代理,我推荐此列表 -- that 参考拥有构建在线程、Twisted、asyncore 和其他技术之上的适合所有口味的代理!

While Twisted, as recommended by @Matthew, is awesome, easier to learn, understand and modify might be this tiny example -- far away from the "production quality" and scalability that Twisted can offer, but, you could start with it to understand the issues better.

For a wide variety of open-source HTTP proxies written in Python, I recommend this list -- that reference has proxies for all tastes built on top of threading, Twisted, asyncore, and other technologies yet!

云醉月微眠 2024-07-30 09:50:26

查看 Tiny HTTP Proxy (1),当然还有相关文档 (2)。 它基本上是运行服务器并处理请求。

(1) http://www.oki-osk.jp/esc/python/代理/
(2) http://docs.python.org/library/basehttpserver.html

Have a look at Tiny HTTP Proxy (1) and of course the related docs (2). It's basically running a server and handling requests.

(1) http://www.oki-osk.jp/esc/python/proxy/
(2) http://docs.python.org/library/basehttpserver.html

献世佛 2024-07-30 09:50:26

WSGI 可能更容易理解。 因此,我将把paste.proxy 扔在那里,作为构建的基础或作为参考。

http://pythonpaste.org/modules/proxy.html

WSGI may be a little easier to get your head around. So I'll throw paste.proxy out there either as something to build on or as a reference.

http://pythonpaste.org/modules/proxy.html

衣神在巴黎 2024-07-30 09:50:26

http://twistedmatrix.com/

适合任何网络需求的优秀库。

http://twistedmatrix.com/

Great library for any networking needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文