aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-08-17 23:49:08 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-08-17 23:49:08 +0200
commit0acda9a684b860ff59642d563beda8e10c8cf253 (patch)
treeb8566d20b1f688dd0c07d1aa2397e29f3b59dc96
parentbb2ce689a91de64d4e6b2191760399255f9eba6a (diff)
downloadmitmproxy-0acda9a684b860ff59642d563beda8e10c8cf253.tar.gz
mitmproxy-0acda9a684b860ff59642d563beda8e10c8cf253.tar.bz2
mitmproxy-0acda9a684b860ff59642d563beda8e10c8cf253.zip
fix #324
-rw-r--r--libmproxy/script.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/libmproxy/script.py b/libmproxy/script.py
index e9716696..b8d6e731 100644
--- a/libmproxy/script.py
+++ b/libmproxy/script.py
@@ -108,14 +108,19 @@ class Script:
return (False, None)
-def _handle_concurrent_reply(fn, o, args=[], kwargs={}):
- reply = o.reply
- o.reply = controller.DummyReply()
- if hasattr(reply, "q"):
- o.reply.q = reply.q
+def _handle_concurrent_reply(fn, o, *args, **kwargs):
+ # Make first call to o.reply a no op
+ original_reply = o.reply
+
+ def restore_original_reply():
+ o.reply = original_reply
+ if hasattr(original_reply, "q"):
+ restore_original_reply.q = original_reply.q
+ o.reply = restore_original_reply
+
def run():
fn(*args, **kwargs)
- reply()
+ o.reply()
threading.Thread(target=run, name="ScriptThread").start()
@@ -123,10 +128,10 @@ def concurrent(fn):
if fn.func_name in ["request", "response", "error"]:
def _concurrent(ctx, flow):
r = getattr(flow, fn.func_name)
- _handle_concurrent_reply(fn, r, [ctx, flow])
+ _handle_concurrent_reply(fn, r, ctx, flow)
return _concurrent
elif fn.func_name in ["clientconnect", "serverconnect", "clientdisconnect"]:
def _concurrent(ctx, conn):
- _handle_concurrent_reply(fn, conn, [ctx, conn])
+ _handle_concurrent_reply(fn, conn, ctx, conn)
return _concurrent
raise NotImplementedError("Concurrent decorator not supported for this method.")