aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/script
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-06-08 10:44:20 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-06-08 10:44:20 +1200
commita388ddfd781fd05a414c07cac8446ef151cbd1d2 (patch)
treead0181e2bfd3408c4e5398e5959da914612dc54b /mitmproxy/script
parent982077ec31ddffeab9830a02b425c35cb0b0dac5 (diff)
downloadmitmproxy-a388ddfd781fd05a414c07cac8446ef151cbd1d2.tar.gz
mitmproxy-a388ddfd781fd05a414c07cac8446ef151cbd1d2.tar.bz2
mitmproxy-a388ddfd781fd05a414c07cac8446ef151cbd1d2.zip
A new interface for reply
Reply is now explicit - it's no longer a callable itself. Instead, we have: reply.kill() - kill the flow reply.ack() - ack, but don't send anything reply.send(message) - send a response This is part of an incremental move to detach reply from our flow objects, and unify the script and handler interfaces.
Diffstat (limited to 'mitmproxy/script')
-rw-r--r--mitmproxy/script/concurrent.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/mitmproxy/script/concurrent.py b/mitmproxy/script/concurrent.py
index 43d0d328..b81f2ab1 100644
--- a/mitmproxy/script/concurrent.py
+++ b/mitmproxy/script/concurrent.py
@@ -4,6 +4,7 @@ offload computations from mitmproxy's main master thread.
"""
from __future__ import absolute_import, print_function, division
+from mitmproxy import controller
import threading
@@ -14,15 +15,15 @@ class ReplyProxy(object):
self.script_thread = script_thread
self.master_reply = None
- def __call__(self, *args):
+ def send(self, message):
if self.master_reply is None:
- self.master_reply = args
+ self.master_reply = message
self.script_thread.start()
return
- self.reply_func(*args)
+ self.reply_func(message)
def done(self):
- self.reply_func(*self.master_reply)
+ self.reply_func.send(self.master_reply)
def __getattr__(self, k):
return getattr(self.reply_func, k)
@@ -49,17 +50,11 @@ class ScriptThread(threading.Thread):
def concurrent(fn):
- if fn.__name__ in (
- "request",
- "response",
- "error",
- "clientconnect",
- "serverconnect",
- "clientdisconnect",
- "next_layer"):
- def _concurrent(ctx, obj):
- _handle_concurrent_reply(fn, obj, ctx, obj)
-
- return _concurrent
- raise NotImplementedError(
- "Concurrent decorator not supported for '%s' method." % fn.__name__)
+ if fn.__name__ not in controller.Events:
+ raise NotImplementedError(
+ "Concurrent decorator not supported for '%s' method." % fn.__name__
+ )
+
+ def _concurrent(ctx, obj):
+ _handle_concurrent_reply(fn, obj, ctx, obj)
+ return _concurrent