aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorHeikki Hannikainen <hessu@he.fi>2012-02-16 16:33:27 +0200
committerHeikki Hannikainen <hessu@he.fi>2012-02-16 16:33:27 +0200
commita82ac9eaf0ccc0f7c9f9588e8f76e213a6a5330b (patch)
treeafe8e2afb96e657de2d58d5e3bc02b4a385191a4 /libmproxy/proxy.py
parentf25156a6377b89ea34899fb61a94694361a7e511 (diff)
downloadmitmproxy-a82ac9eaf0ccc0f7c9f9588e8f76e213a6a5330b.tar.gz
mitmproxy-a82ac9eaf0ccc0f7c9f9588e8f76e213a6a5330b.tar.bz2
mitmproxy-a82ac9eaf0ccc0f7c9f9588e8f76e213a6a5330b.zip
Implemented reverse proxy mode: -R upstreamhost:port makes the
proxy accept a 'GET / HTTP/1.0' request and fill up the destination host and port from the ones given with -R (for example, "-R localhost:80").
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 1fce46d6..3b853e94 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -22,13 +22,14 @@ class ProxyError(Exception):
class ProxyConfig:
- def __init__(self, certfile = None, ciphers = None, cacert = None, cert_wait_time=0, body_size_limit = None):
+ def __init__(self, certfile = None, ciphers = None, cacert = None, cert_wait_time=0, body_size_limit = None, reverse_upstream=None):
self.certfile = certfile
self.ciphers = ciphers
self.cacert = cacert
self.certdir = None
self.cert_wait_time = cert_wait_time
self.body_size_limit = body_size_limit
+ self.reverse_upstream = reverse_upstream
def read_chunked(fp, limit):
@@ -347,6 +348,12 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
self.rfile = FileLike(self.connection)
self.wfile = FileLike(self.connection)
method, scheme, host, port, path, httpminor = parse_request_line(self.rfile.readline())
+ # if we're in reverse proxy mode, we only get the path and version in the request
+ # and need to fill up host and port from the configuration
+ if self.config.reverse_upstream:
+ scheme = 'http'
+ host, port = self.config.reverse_upstream.split(':')
+ port = int(port)
if scheme is None:
scheme = "https"
headers = flow.Headers()
@@ -488,7 +495,8 @@ def process_proxy_options(parser, options):
cacert = cacert,
ciphers = options.ciphers,
cert_wait_time = options.cert_wait_time,
- body_size_limit = body_size_limit
+ body_size_limit = body_size_limit,
+ reverse_upstream = options.reverse_upstream
)