mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
fix #324
This commit is contained in:
parent
bb2ce689a9
commit
0acda9a684
@ -108,14 +108,19 @@ class Script:
|
|||||||
return (False, None)
|
return (False, None)
|
||||||
|
|
||||||
|
|
||||||
def _handle_concurrent_reply(fn, o, args=[], kwargs={}):
|
def _handle_concurrent_reply(fn, o, *args, **kwargs):
|
||||||
reply = o.reply
|
# Make first call to o.reply a no op
|
||||||
o.reply = controller.DummyReply()
|
original_reply = o.reply
|
||||||
if hasattr(reply, "q"):
|
|
||||||
o.reply.q = reply.q
|
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():
|
def run():
|
||||||
fn(*args, **kwargs)
|
fn(*args, **kwargs)
|
||||||
reply()
|
o.reply()
|
||||||
threading.Thread(target=run, name="ScriptThread").start()
|
threading.Thread(target=run, name="ScriptThread").start()
|
||||||
|
|
||||||
|
|
||||||
@ -123,10 +128,10 @@ def concurrent(fn):
|
|||||||
if fn.func_name in ["request", "response", "error"]:
|
if fn.func_name in ["request", "response", "error"]:
|
||||||
def _concurrent(ctx, flow):
|
def _concurrent(ctx, flow):
|
||||||
r = getattr(flow, fn.func_name)
|
r = getattr(flow, fn.func_name)
|
||||||
_handle_concurrent_reply(fn, r, [ctx, flow])
|
_handle_concurrent_reply(fn, r, ctx, flow)
|
||||||
return _concurrent
|
return _concurrent
|
||||||
elif fn.func_name in ["clientconnect", "serverconnect", "clientdisconnect"]:
|
elif fn.func_name in ["clientconnect", "serverconnect", "clientdisconnect"]:
|
||||||
def _concurrent(ctx, conn):
|
def _concurrent(ctx, conn):
|
||||||
_handle_concurrent_reply(fn, conn, [ctx, conn])
|
_handle_concurrent_reply(fn, conn, ctx, conn)
|
||||||
return _concurrent
|
return _concurrent
|
||||||
raise NotImplementedError("Concurrent decorator not supported for this method.")
|
raise NotImplementedError("Concurrent decorator not supported for this method.")
|
||||||
|
Loading…
Reference in New Issue
Block a user