aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/flow.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-02-02 11:44:28 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-02-02 11:44:28 +1300
commitdb99da6af560f80bc169979f6d8681de3879acf2 (patch)
tree14da7a5b00704814376dc29b2489bf85f29fe48d /libmproxy/flow.py
parent8d37ff81e6e256180fdb8e266df4f861e8593c82 (diff)
downloadmitmproxy-db99da6af560f80bc169979f6d8681de3879acf2.tar.gz
mitmproxy-db99da6af560f80bc169979f6d8681de3879acf2.tar.bz2
mitmproxy-db99da6af560f80bc169979f6d8681de3879acf2.zip
Improve script handling.
- Display output in external viewer when script exits with error. - Add a "changed" indicator to show if a request can be reverted.
Diffstat (limited to 'libmproxy/flow.py')
-rw-r--r--libmproxy/flow.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index d3bba4b3..cf39bed9 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -6,7 +6,12 @@ import subprocess, base64, sys
from contrib import bson
import proxy, threading
-class RunException(Exception): pass
+class RunException(Exception):
+ def __init__(self, msg, returncode, errout):
+ Exception.__init__(self, msg)
+ self.returncode = returncode
+ self.errout = errout
+
class ReplayConnection:
pass
@@ -58,6 +63,7 @@ class Flow:
Returns a (flow, stderr output) tuple, or raises RunException if
there's an error.
"""
+ self.backup()
data = self.script_serialize()
try:
p = subprocess.Popen(
@@ -67,13 +73,21 @@ class Flow:
stderr=subprocess.PIPE,
)
except OSError, e:
- raise RunException(e.args[1])
+ raise RunException(e.args[1], None, None)
so, se = p.communicate(data)
if p.returncode:
- raise RunException("Script returned error code %s"%p.returncode)
+ raise RunException(
+ "Script returned error code %s"%p.returncode,
+ p.returncode,
+ se
+ )
f = Flow.script_deserialize(so)
if not f:
- raise RunException("Invalid response from script.")
+ raise RunException(
+ "Invalid response from script.",
+ p.returncode,
+ se
+ )
return f, se
def dump(self):
@@ -106,6 +120,14 @@ class Flow:
def __eq__(self, other):
return self.get_state() == other.get_state()
+ def modified(self):
+ # FIXME: Save a serialization in backup, compare current with
+ # backup to detect if flow has _really_ been modified.
+ if self._backup:
+ return True
+ else:
+ return False
+
def backup(self):
if not self._backup:
self._backup = [
@@ -119,6 +141,7 @@ class Flow:
if self._backup:
restore = [i.copy() if i else None for i in self._backup]
self.connection, self.request, self.response, self.error = restore
+ self._backup = None
def match(self, pattern):
if pattern: