aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-12-23 20:33:42 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-12-23 20:33:42 +0100
commit2861d99de4d329bcba0a3c2193523398a22673c0 (patch)
tree0aa1a2aae666c2909285a6fd5049f2ef7d6d8ebc /libmproxy/protocol
parent459772a8ef79ac0adeaeba56577972e86074265e (diff)
downloadmitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.tar.gz
mitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.tar.bz2
mitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.zip
web: intercept feature
Diffstat (limited to 'libmproxy/protocol')
-rw-r--r--libmproxy/protocol/http.py29
-rw-r--r--libmproxy/protocol/primitives.py32
2 files changed, 32 insertions, 29 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index d3945579..c6e67498 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -882,7 +882,7 @@ class HTTPFlow(Flow):
The following additional attributes are exposed:
- intercepting: Is this flow currently being intercepted?
+ intercepted: Is this flow currently being intercepted?
live: Does this flow have a live client connection?
"""
@@ -893,9 +893,6 @@ class HTTPFlow(Flow):
self.response = None
"""@type: HTTPResponse"""
- # FIXME: Should that rather be an attribute of Flow?
- self.intercepting = False
-
_stateobject_attributes = Flow._stateobject_attributes.copy()
_stateobject_attributes.update(
request=HTTPRequest,
@@ -942,30 +939,6 @@ class HTTPFlow(Flow):
return f(self)
return True
- def kill(self, master):
- """
- Kill this request.
- """
- self.error = Error("Connection killed")
- self.intercepting = False
- self.reply(KILL)
- self.reply = controller.DummyReply()
- master.handle_error(self)
-
- def intercept(self):
- """
- Intercept this Flow. Processing will stop until accept_intercept is
- called.
- """
- self.intercepting = True
-
- def accept_intercept(self):
- """
- Continue with the flow - called after an intercept().
- """
- self.intercepting = False
- self.reply()
-
def replace(self, pattern, repl, *args, **kwargs):
"""
Replaces a regular expression pattern with repl in both request and
diff --git a/libmproxy/protocol/primitives.py b/libmproxy/protocol/primitives.py
index 34526d01..49c71c9f 100644
--- a/libmproxy/protocol/primitives.py
+++ b/libmproxy/protocol/primitives.py
@@ -71,14 +71,18 @@ class Flow(stateobject.StateObject):
self.error = None
"""@type: Error"""
+ self.intercepted = False
+ """@type: bool"""
self._backup = None
+ self.reply = None
_stateobject_attributes = dict(
id=str,
error=Error,
client_conn=ClientConnection,
server_conn=ServerConnection,
- type=str
+ type=str,
+ intercepted=bool
)
def get_state(self, short=False):
@@ -124,6 +128,32 @@ class Flow(stateobject.StateObject):
self.load_state(self._backup)
self._backup = None
+ def kill(self, master):
+ """
+ Kill this request.
+ """
+ self.error = Error("Connection killed")
+ self.intercepted = False
+ self.reply(KILL)
+ master.handle_error(self)
+
+ def intercept(self, master):
+ """
+ Intercept this Flow. Processing will stop until accept_intercept is
+ called.
+ """
+ self.intercepted = True
+ master.handle_intercept(self)
+
+ def accept_intercept(self, master):
+ """
+ Continue with the flow - called after an intercept().
+ """
+ self.intercepted = False
+ self.reply()
+ master.handle_accept_intercept(self)
+
+
class ProtocolHandler(object):
"""