aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-01-26 14:52:03 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-01-26 14:52:03 +1300
commit29d800767802ffc17c3577aaebfaf59221e0fb7e (patch)
treecaa6da763476c7e9384c7eb0a77062814eb37980 /libmproxy/proxy.py
parent7983dbb26a023db149a6e3e91f19fc7171680534 (diff)
downloadmitmproxy-29d800767802ffc17c3577aaebfaf59221e0fb7e.tar.gz
mitmproxy-29d800767802ffc17c3577aaebfaf59221e0fb7e.tar.bz2
mitmproxy-29d800767802ffc17c3577aaebfaf59221e0fb7e.zip
Add serialization hooks to flows and flow component objects.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 9f87f80e..f3b9fe53 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -88,6 +88,33 @@ class Request(controller.Msg):
self.kill = False
controller.Msg.__init__(self)
+ def get_state(self):
+ return dict(
+ host = self.host,
+ port = self.port,
+ scheme = self.scheme,
+ method = self.method,
+ path = self.path,
+ headers = self.headers.get_state(),
+ content = self.content
+ )
+
+ @classmethod
+ def from_state(klass, state):
+ return klass(
+ None,
+ state["host"],
+ state["port"],
+ state["scheme"],
+ state["method"],
+ state["path"],
+ utils.Headers.from_state(state["headers"]),
+ state["content"]
+ )
+
+ def __eq__(self, other):
+ return self.get_state() == other.get_state()
+
def copy(self):
c = copy.copy(self)
c.headers = self.headers.copy()
@@ -137,6 +164,29 @@ class Response(controller.Msg):
self.kill = False
controller.Msg.__init__(self)
+ def get_state(self):
+ return dict(
+ code = self.code,
+ proto = self.proto,
+ msg = self.msg,
+ headers = self.headers.get_state(),
+ content = self.content
+ )
+
+ @classmethod
+ def from_state(klass, request, state):
+ return klass(
+ request,
+ state["code"],
+ state["proto"],
+ state["msg"],
+ utils.Headers.from_state(state["headers"]),
+ state["content"]
+ )
+
+ def __eq__(self, other):
+ return self.get_state() == other.get_state()
+
def copy(self):
c = copy.copy(self)
c.headers = self.headers.copy()
@@ -181,6 +231,21 @@ class Error(controller.Msg):
def copy(self):
return copy.copy(self)
+ def get_state(self):
+ return dict(
+ msg = self.msg,
+ )
+
+ @classmethod
+ def from_state(klass, state):
+ return klass(
+ None,
+ state["msg"],
+ )
+
+ def __eq__(self, other):
+ return self.get_state() == other.get_state()
+
class FileLike:
def __init__(self, o):