aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/message.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-02-08 09:52:29 +0100
committerThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-02-08 09:52:29 +0100
commit4ee1ad88fc440164985c8efc50c0be133a0053bc (patch)
tree210635d4aa964873f8054c80fcbeb2e9f94ce6ab /netlib/http/message.py
parent4873547de3c65ba7c14cace4bca7b17368b2900d (diff)
parent655b521749efd5a600d342a1d95b67d32da280a8 (diff)
downloadmitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.tar.gz
mitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.tar.bz2
mitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.zip
Merge pull request #120 from mitmproxy/model-cleanup
Model Cleanup
Diffstat (limited to 'netlib/http/message.py')
-rw-r--r--netlib/http/message.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/netlib/http/message.py b/netlib/http/message.py
index 28f55fa2..e3d8ce37 100644
--- a/netlib/http/message.py
+++ b/netlib/http/message.py
@@ -4,9 +4,9 @@ import warnings
import six
+from .headers import Headers
from .. import encoding, utils
-
CONTENT_MISSING = 0
if six.PY2: # pragma: nocover
@@ -18,7 +18,7 @@ else:
_always_bytes = lambda x: utils.always_bytes(x, "utf-8", "surrogateescape")
-class MessageData(object):
+class MessageData(utils.Serializable):
def __eq__(self, other):
if isinstance(other, MessageData):
return self.__dict__ == other.__dict__
@@ -27,8 +27,24 @@ class MessageData(object):
def __ne__(self, other):
return not self.__eq__(other)
+ def set_state(self, state):
+ for k, v in state.items():
+ if k == "headers":
+ v = Headers.from_state(v)
+ setattr(self, k, v)
+
+ def get_state(self):
+ state = vars(self).copy()
+ state["headers"] = state["headers"].get_state()
+ return state
+
+ @classmethod
+ def from_state(cls, state):
+ state["headers"] = Headers.from_state(state["headers"])
+ return cls(**state)
+
-class Message(object):
+class Message(utils.Serializable):
def __init__(self, data):
self.data = data
@@ -40,6 +56,16 @@ class Message(object):
def __ne__(self, other):
return not self.__eq__(other)
+ def get_state(self):
+ return self.data.get_state()
+
+ def set_state(self, state):
+ self.data.set_state(state)
+
+ @classmethod
+ def from_state(cls, state):
+ return cls(**state)
+
@property
def headers(self):
"""