diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py index 87f45976b..4b2357f89 100644 --- a/mitmproxy/addons/dumper.py +++ b/mitmproxy/addons/dumper.py @@ -27,9 +27,10 @@ def colorful(line, styles): class Dumper: - def __init__(self, outfile=sys.stdout): + def __init__(self, outfile=sys.stdout, errfile=sys.stderr): self.filter: flowfilter.TFilter = None self.outfp: typing.io.TextIO = outfile + self.errfp: typing.io.TextIO = errfile def load(self, loader): loader.add_option( @@ -70,6 +71,13 @@ class Dumper: if self.outfp: self.outfp.flush() + def echo_error(self, text, ident=None, **style): + if ident: + text = indent(ident, text) + click.secho(text, file=self.errfp, **style) + if self.errfp: + self.errfp.flush() + def _echo_headers(self, headers): for k, v in headers.fields: k = strutils.bytes_to_escaped_str(k) @@ -243,7 +251,7 @@ class Dumper: self.echo_flow(f) def websocket_error(self, f): - self.echo( + self.echo_error( "Error in WebSocket connection to {}: {}".format( human.format_address(f.server_conn.address), f.error ), @@ -268,7 +276,7 @@ class Dumper: f.close_reason)) def tcp_error(self, f): - self.echo( + self.echo_error( "Error in TCP connection to {}: {}".format( human.format_address(f.server_conn.address), f.error ),