跳转到主要内容

一个小型HTTP代理实现

项目描述

本模块通过扩展BaseHTTPServer实现了一个小型HTTP代理。支持GETHEADPOSTPUTDELETECONNECT方法。

最新版本可以通过PyPI安装

$ pip install httproxy

或者

$ easy_install httproxy

源代码仓库和问题跟踪器维护在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(或在Windows上为%HOME%\.httproxy\config

  • 在命令行上的--configfile中指定的值

主部分中设置的名称来源于长命令行选项名称。

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将能够在启动时自动删除旧的pid文件。

变更日志

0.9.0

  • 从文件中读取配置的能力(--configfile

  • 指定代理将绑定到的地址的能力(--host

  • 记录发送和接收的标题的能力(--verbose

  • 更好的进程管理:pid文件支持,更详细的进程标题(带有可选的setproctitle依赖项)

  • 修复了虚假的[Errno 54] Connection reset by peer回溯

  • 在接收到SIGHUPSIGINTSIGTERM时正确关闭

  • 主要代码重构

  • 仅与Python 2.6和2.7兼容:需要docoptconfigparser

0.3.1

  • 添加了基本的FTP文件检索

  • 添加了自定义日志方法

  • 添加了使其作为独立应用程序运行的代码

Mitko Haralanov在2009年升级。

0.2.1

作者

脚本基于Suzuki Hisao和Mitko Haralanov的工作,目前由Łukasz Langa维护。

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

httproxy-0.9.0.tar.gz (9.1 kB 查看散列)

上传时间 源代码

由以下支持