aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorHenrik Nordstrom <henrik@henriknordstrom.net>2010-11-17 14:11:56 +0100
committerHenrik Nordstrom <henrik@henriknordstrom.net>2011-02-10 02:59:51 +0100
commitd11dd742d8593087959b6f1e0d9cc1f956dee03e (patch)
tree9ac076b44004556cfc83682999a4774639759868 /libmproxy/proxy.py
parent4bae297fbbe294a962116f574ca1b8ae434e0886 (diff)
downloadmitmproxy-d11dd742d8593087959b6f1e0d9cc1f956dee03e.tar.gz
mitmproxy-d11dd742d8593087959b6f1e0d9cc1f956dee03e.tar.bz2
mitmproxy-d11dd742d8593087959b6f1e0d9cc1f956dee03e.zip
Simple record & playback functionality
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index e3eace3b..631e2470 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -124,6 +124,7 @@ def parse_request_line(request):
class Request(controller.Msg):
FMT = '%s %s HTTP/1.1\r\n%s\r\n%s'
+ FMT_PROXY = '%s %s://%s:%s%s HTTP/1.1\r\n%s\r\n%s'
def __init__(self, client_conn, host, port, scheme, method, path, headers, content, timestamp=None):
self.client_conn = client_conn
self.host, self.port, self.scheme = host, port, scheme
@@ -132,6 +133,9 @@ class Request(controller.Msg):
self.close = False
controller.Msg.__init__(self)
+ def is_cached(self):
+ return False
+
def get_state(self):
return dict(
host = self.host,
@@ -189,7 +193,10 @@ class Request(controller.Msg):
def short(self):
return "%s %s"%(self.method, self.url())
- def assemble(self):
+ def assemble_proxy(self):
+ return self.assemble(True)
+
+ def assemble(self, _proxy = False):
"""
Assembles the request for transmission to the server. We make some
modifications to make sure interception works properly.
@@ -210,8 +217,10 @@ class Request(controller.Msg):
content = ""
if self.close:
headers["connection"] = ["close"]
- data = (self.method, self.path, str(headers), content)
- return self.FMT%data
+ if not _proxy:
+ return self.FMT % (self.method, self.path, str(headers), content)
+ else:
+ return self.FMT_PROXY % (self.method, self.scheme, self.host, self.port, self.path, str(headers), content)
class Response(controller.Msg):
@@ -221,6 +230,7 @@ class Response(controller.Msg):
self.code, self.msg = code, msg
self.headers, self.content = headers, content
self.timestamp = timestamp or time.time()
+ self.cached = False
controller.Msg.__init__(self)
def get_state(self):
@@ -256,6 +266,9 @@ class Response(controller.Msg):
def is_response(self):
return True
+ def is_cached(self):
+ return self.cached
+
def short(self):
return "%s %s"%(self.code, self.msg)