aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-09-24 18:41:32 +0200
committerGitHub <noreply@github.com>2016-09-24 18:41:32 +0200
commit258958e073d08ce4e523be9e0cf7784ed4ba2b8e (patch)
treee1027fcd7f7406374f1ffeb11242f3014d955f2f
parent9142da1a7d6e87147a8ed92ae027d55ac935eb85 (diff)
parent276b467b0e012129da91c0069eebb64fdc4179b6 (diff)
downloadmitmproxy-258958e073d08ce4e523be9e0cf7784ed4ba2b8e.tar.gz
mitmproxy-258958e073d08ce4e523be9e0cf7784ed4ba2b8e.tar.bz2
mitmproxy-258958e073d08ce4e523be9e0cf7784ed4ba2b8e.zip
Merge pull request #1574 from mhils/issue-1393
Fix #1393
-rw-r--r--mitmproxy/console/flowlist.py6
-rw-r--r--mitmproxy/console/flowview.py6
-rw-r--r--mitmproxy/exceptions.py4
-rw-r--r--mitmproxy/flow/master.py33
-rw-r--r--mitmproxy/protocol/http_replay.py2
5 files changed, 32 insertions, 19 deletions
diff --git a/mitmproxy/console/flowlist.py b/mitmproxy/console/flowlist.py
index c052de7b..a05ed659 100644
--- a/mitmproxy/console/flowlist.py
+++ b/mitmproxy/console/flowlist.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, division
import urwid
import netlib.http.url
+from mitmproxy import exceptions
from mitmproxy.console import common
from mitmproxy.console import signals
from mitmproxy.flow import export
@@ -180,7 +181,10 @@ class ConnectionItem(urwid.WidgetWrap):
self.state.enable_marked_filter()
signals.flowlist_change.send(self)
elif key == "r":
- self.master.replay_request(self.flow)
+ try:
+ self.master.replay_request(self.flow)
+ except exceptions.ReplayException as e:
+ signals.add_log("Replay error: %s" % e, "warn")
signals.flowlist_change.send(self)
elif key == "S":
def stop_server_playback(response):
diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py
index add10527..4643863c 100644
--- a/mitmproxy/console/flowview.py
+++ b/mitmproxy/console/flowview.py
@@ -5,6 +5,7 @@ import os
import sys
import urwid
+from mitmproxy import exceptions
from typing import Optional, Union # noqa
from mitmproxy import contentviews
@@ -544,7 +545,10 @@ class FlowView(tabs.Tabs):
elif key == "p":
self.view_prev_flow(self.flow)
elif key == "r":
- self.master.replay_request(self.flow)
+ try:
+ self.master.replay_request(self.flow)
+ except exceptions.ReplayException as e:
+ signals.add_log("Replay error: %s" % e, "warn")
signals.flow_change.send(self, flow = self.flow)
elif key == "V":
if self.flow.modified():
diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py
index 6873215c..7fca584a 100644
--- a/mitmproxy/exceptions.py
+++ b/mitmproxy/exceptions.py
@@ -97,7 +97,3 @@ class OptionsError(Exception):
class AddonError(Exception):
pass
-
-
-class ReplayError(Exception):
- pass
diff --git a/mitmproxy/flow/master.py b/mitmproxy/flow/master.py
index 94b46f3f..80f633cd 100644
--- a/mitmproxy/flow/master.py
+++ b/mitmproxy/flow/master.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
import os
import sys
-from typing import List, Optional, Set # noqa
+from typing import Optional # noqa
import netlib.exceptions
from mitmproxy import controller
@@ -138,37 +138,44 @@ class FlowMaster(controller.Master):
def replay_request(self, f, block=False):
"""
- Returns an http_replay.RequestReplayThred object.
- May raise exceptions.ReplayError.
+ Replay a HTTP request to receive a new response from the server.
+
+ Args:
+ f: The flow to replay.
+ block: If True, this function will wait for the replay to finish.
+ This causes a deadlock if activated in the main thread.
+
+ Returns:
+ The thread object doing the replay.
+
+ Raises:
+ exceptions.ReplayException, if the flow is in a state
+ where it is ineligible for replay.
"""
+
if f.live:
- raise exceptions.ReplayError(
+ raise exceptions.ReplayException(
"Can't replay live flow."
)
if f.intercepted:
- raise exceptions.ReplayError(
+ raise exceptions.ReplayException(
"Can't replay intercepted flow."
)
if f.request.raw_content is None:
- raise exceptions.ReplayError(
+ raise exceptions.ReplayException(
"Can't replay flow with missing content."
)
if not f.request:
- raise exceptions.ReplayError(
+ raise exceptions.ReplayException(
"Can't replay flow with missing request."
)
f.backup()
f.request.is_replay = True
- # TODO: We should be able to remove this.
- if "Content-Length" in f.request.headers:
- f.request.headers["Content-Length"] = str(len(f.request.raw_content))
-
f.response = None
f.error = None
- # FIXME: process through all addons?
- # self.process_new_request(f)
+
rt = http_replay.RequestReplayThread(
self.server.config,
f,
diff --git a/mitmproxy/protocol/http_replay.py b/mitmproxy/protocol/http_replay.py
index 877eaa22..5e527f1d 100644
--- a/mitmproxy/protocol/http_replay.py
+++ b/mitmproxy/protocol/http_replay.py
@@ -22,6 +22,7 @@ class RequestReplayThread(basethread.BaseThread):
processed.
"""
self.config, self.flow = config, flow
+ flow.live = True
if event_queue:
self.channel = controller.Channel(event_queue, should_exit)
else:
@@ -104,5 +105,6 @@ class RequestReplayThread(basethread.BaseThread):
self.channel.tell("log", Log(traceback.format_exc(), "error"))
finally:
r.first_line_format = first_line_format_backup
+ self.flow.live = False
if server:
server.finish()