aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-04-02 21:03:36 +0200
committerMaximilian Hils <git@maximilianhils.com>2016-04-02 21:03:36 +0200
commit3a1486183cbe743427179096dd92181865aad638 (patch)
tree5f9cbafaecb988e17a5aa1927fa9b69f717aa6a4
parent4bdf7e035ea83a8c59a7d10087b3a71ea8ff29bc (diff)
downloadmitmproxy-3a1486183cbe743427179096dd92181865aad638.tar.gz
mitmproxy-3a1486183cbe743427179096dd92181865aad638.tar.bz2
mitmproxy-3a1486183cbe743427179096dd92181865aad638.zip
fix #1061
-rw-r--r--mitmproxy/flow.py13
-rw-r--r--mitmproxy/script/concurrent.py27
2 files changed, 19 insertions, 21 deletions
diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py
index fbf102b5..63bd1471 100644
--- a/mitmproxy/flow.py
+++ b/mitmproxy/flow.py
@@ -806,7 +806,7 @@ class FlowMaster(controller.Master):
response.is_replay = True
if self.refresh_server_playback:
response.refresh()
- flow.reply(response)
+ flow.response = response
if self.server_playback.count() == 0:
self.stop_server_playback()
return True
@@ -905,11 +905,11 @@ class FlowMaster(controller.Master):
def load_flows_file(self, path):
path = os.path.expanduser(path)
try:
- f = file(path, "rb")
- freader = FlowReader(f)
+ with open(path, "rb") as f:
+ freader = FlowReader(f)
+ return self.load_flows(freader)
except IOError as v:
raise FlowReadError(v.strerror)
- return self.load_flows(freader)
def process_new_request(self, f):
if self.stickycookie_state:
@@ -924,11 +924,8 @@ class FlowMaster(controller.Master):
if self.server_playback:
pb = self.do_server_playback(f)
- if not pb:
- if self.kill_nonreplay:
+ if not pb and self.kill_nonreplay:
f.kill(self)
- else:
- f.reply()
def process_new_response(self, f):
if self.stickycookie_state:
diff --git a/mitmproxy/script/concurrent.py b/mitmproxy/script/concurrent.py
index 57ee37de..2f25e78c 100644
--- a/mitmproxy/script/concurrent.py
+++ b/mitmproxy/script/concurrent.py
@@ -8,22 +8,23 @@ import threading
class ReplyProxy(object):
- def __init__(self, original_reply, script_thread):
- self.original_reply = original_reply
+ def __init__(self, reply_func, script_thread):
+ self.reply_func = reply_func
self.script_thread = script_thread
- self._ignore_call = True
- self.lock = threading.Lock()
+ self.master_reply = None
- def __call__(self, *args, **kwargs):
- with self.lock:
- if self._ignore_call:
- self.script_thread.start()
- self._ignore_call = False
- return
- self.original_reply(*args, **kwargs)
+ def __call__(self, *args):
+ if self.master_reply is None:
+ self.master_reply = args
+ self.script_thread.start()
+ return
+ self.reply_func(*args)
+
+ def done(self):
+ self.reply_func(*self.master_reply)
def __getattr__(self, k):
- return getattr(self.original_reply, k)
+ return getattr(self.reply_func, k)
def _handle_concurrent_reply(fn, o, *args, **kwargs):
@@ -34,7 +35,7 @@ def _handle_concurrent_reply(fn, o, *args, **kwargs):
def run():
fn(*args, **kwargs)
# If the script did not call .reply(), we have to do it now.
- reply_proxy()
+ reply_proxy.done()
script_thread = ScriptThread(target=run)