diff options
Diffstat (limited to 'mitmproxy/dump.py')
-rw-r--r-- | mitmproxy/dump.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index c308adf0..aae397cd 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -5,9 +5,9 @@ import click import itertools from netlib import tcp -import netlib.utils +from netlib.utils import bytes_to_escaped_str, pretty_size from . import flow, filt, contentviews -from .exceptions import ContentViewException, FlowReadException +from .exceptions import ContentViewException, FlowReadException, ScriptException class DumpError(Exception): @@ -125,9 +125,10 @@ class DumpMaster(flow.FlowMaster): scripts = options.scripts or [] for command in scripts: - err = self.load_script(command, use_reloader=True) - if err: - raise DumpError(err) + try: + self.load_script(command, use_reloader=True) + except ScriptException as e: + raise DumpError(str(e)) if options.rfile: try: @@ -174,8 +175,8 @@ class DumpMaster(flow.FlowMaster): if self.o.flow_detail >= 2: headers = "\r\n".join( "{}: {}".format( - click.style(k, fg="blue", bold=True), - click.style(v, fg="blue")) + click.style(bytes_to_escaped_str(k), fg="blue", bold=True), + click.style(bytes_to_escaped_str(v), fg="blue")) for k, v in message.headers.fields ) self.echo(headers, indent=4) @@ -237,7 +238,7 @@ class DumpMaster(flow.FlowMaster): stickycookie = "" if flow.client_conn: - client = click.style(flow.client_conn.address.host, bold=True) + client = click.style(bytes_to_escaped_str(flow.client_conn.address.host), bold=True) else: client = click.style("[replay]", fg="yellow", bold=True) @@ -246,12 +247,12 @@ class DumpMaster(flow.FlowMaster): GET="green", DELETE="red" ).get(method.upper(), "magenta") - method = click.style(method, fg=method_color, bold=True) + method = click.style(bytes_to_escaped_str(method), fg=method_color, bold=True) if self.showhost: url = flow.request.pretty_url else: url = flow.request.url - url = click.style(url, bold=True) + url = click.style(bytes_to_escaped_str(url), bold=True) httpversion = "" if flow.request.http_version not in ("HTTP/1.1", "HTTP/1.0"): @@ -281,12 +282,12 @@ class DumpMaster(flow.FlowMaster): elif 400 <= code < 600: code_color = "red" code = click.style(str(code), fg=code_color, bold=True, blink=(code == 418)) - reason = click.style(flow.response.reason, fg=code_color, bold=True) + reason = click.style(bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True) if flow.response.content is None: size = "(content missing)" else: - size = netlib.utils.pretty_size(len(flow.response.content)) + size = pretty_size(len(flow.response.content)) size = click.style(size, bold=True) arrows = click.style("<<", bold=True) @@ -346,5 +347,6 @@ class DumpMaster(flow.FlowMaster): def run(self): # pragma: no cover if self.o.rfile and not self.o.keepserving: + self.unload_scripts() # make sure to trigger script unload events. return - super(DumpMaster, self).run()
\ No newline at end of file + super(DumpMaster, self).run() |