一个小小的http代理实现
httprox的Python项目详细描述
此模块通过扩展BaseHTTPServer实现一个小型http代理。 支持GET、HEAD、POST、PUT、DELETE和CONNECT 方法。
最新版本可以通过PyPI:
$ pip install httproxy
或:
$ easy_install httproxy
source code repository和issue tracker保持在 GitHub。
快速启动
用法:
httproxy [options] httproxy [options] <allowed-client> ...
选项:
-h, --help Show this screen. --version Show version and exit. -H, --host HOST Host to bind to [default: 127.0.0.1]. -p, --port PORT Port to bind to [default: 8000]. -l, --logfile PATH Path to the logfile [default: STDOUT]. -i, --pidfile PIDFILE Path to the pidfile [default: httproxy.pid]. -d, --daemon Daemonize (run in the background). The default logfile path is httproxy.log in this case. -c, --configfile CONFIGFILE Path to a configuration file. -v, --verbose Log headers.
启动代理服务器并将其绑定到22222端口 收听并接受连接):
httproxy -p 22222
要启动代理服务器,请将其绑定到22222端口,并告诉它记录所有请求 到文件httproxy.log:
httproxy -p 22222 -l httproxy.log
启动代理服务器以便它只允许来自IP的连接 123.123.123.123:
httproxy 123.123.123.123
要启动绑定到22222端口的代理服务器,请登录到文件httproxy.log,然后运行 后台服务器(作为守护进程):
httproxy -p 22222 -l httproxy.log -d
配置文件
作为命令行参数声明的每个选项都可以使用 配置文件。httproxy查找要读取的以下文件 配置:
- /etc/httproxy/config
- $HOME/.httproxy/config(或%HOME%\.httproxy\config在Windows上)
- 在命令行--configfile中指定的值
main节中设置的名称来自long 命令行选项名称。
allowed-clients部分包含可以访问 代理,每行一个主机名。删除此部分或保留为空以允许 要连接的客户端。
示例文件:
[main] host = localhost port = 8011 logfile = /Users/ambv/.httproxy/log pidfile = /Users/ambv/.httproxy/pid daemon = yes verbose = yes [allowed-clients] localhost 192.168.0.1
注意:命令行选项优先于配置文件设置。
可选依赖项
如果安装setproctitle,则ps报告的进程的名称将 更具描述性。
如果安装psutil,httproxy将能够自动删除过时的 启动时的pidfiles。
更改日志
0.9.0
- 能够从文件中读取配置(--configfile)
- 能够指定代理将绑定到的地址(--host)
- 能够记录发送和接收的邮件头(--verbose)
- 更好的流程管理:pidfile支持,更具描述性的流程标题 (具有可选的setproctitle依赖项)
- 修正了伪[Errno 54] Connection reset by peer回溯
- 接收SIGHUP、SIGINT或SIGTERM时正确关闭
- 主要代码重构
- 仅与Python2.6和2.7兼容:需要^{TT28}$和^{TT29}$
0.2.1
- 2006年由原作者主持的基本版 http://www.oki-osk.jp/esc/python/proxy/