diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py index e94d6a796..12b0c34b1 100644 --- a/mitmproxy/addons/dumper.py +++ b/mitmproxy/addons/dumper.py @@ -2,6 +2,7 @@ import itertools import sys import click +import shutil import typing # noqa @@ -124,6 +125,9 @@ class Dumper: url = flow.request.pretty_url else: url = flow.request.url + terminalWidthLimit = max(shutil.get_terminal_size()[0] - 25, 50) + if self.flow_detail < 1 and len(url) > terminalWidthLimit: + url = url[:terminalWidthLimit] + "…" url = click.style(strutils.escape_control_characters(url), bold=True) http_version = "" diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index 8b15c85b0..d8d2deeb6 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -7,6 +7,7 @@ from mitmproxy.addons import dumper from mitmproxy import exceptions from mitmproxy.tools import dump from mitmproxy import http +import shutil import mock @@ -129,6 +130,14 @@ def test_echo_request_line(): assert "nonstandard" in sio.getvalue() sio.truncate(0) + ctx.configure(d, flow_detail=0, showhost=True) + f = tflow.tflow(client_conn=None, server_conn=True, resp=True) + terminalWidth = max(shutil.get_terminal_size()[0] - 25, 50) + f.request.url = "http://address:22/" + ("x" * terminalWidth) + "textToBeTruncated" + d._echo_request_line(f) + assert "textToBeTruncated" not in sio.getvalue() + sio.truncate(0) + class TestContentView: @mock.patch("mitmproxy.contentviews.auto.ViewAuto.__call__")