From 2861d99de4d329bcba0a3c2193523398a22673c0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 23 Dec 2014 20:33:42 +0100 Subject: web: intercept feature --- libmproxy/protocol/http.py | 29 +---------------------------- libmproxy/protocol/primitives.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 29 deletions(-) (limited to 'libmproxy/protocol') 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): """ -- cgit v1.2.3