aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlymanZerga11 <jacobsunny95@gmail.com>2017-01-05 21:37:20 +0800
committerMaximilian Hils <git@maximilianhils.com>2017-01-05 14:37:20 +0100
commit3ea76a7f3e123a9ad8f05a6f0325e6642c6aa01a (patch)
treee37a5915daae8c2bb8265d60e4108ec6b3d72f9b
parent2335a70b790c555936bfeb260c3605ae3de90c20 (diff)
downloadmitmproxy-3ea76a7f3e123a9ad8f05a6f0325e6642c6aa01a.tar.gz
mitmproxy-3ea76a7f3e123a9ad8f05a6f0325e6642c6aa01a.tar.bz2
mitmproxy-3ea76a7f3e123a9ad8f05a6f0325e6642c6aa01a.zip
Controls the length of URL displayed using the -d option (#1903)
-rw-r--r--mitmproxy/addons/dumper.py4
-rw-r--r--test/mitmproxy/addons/test_dumper.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py
index e94d6a79..12b0c34b 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 8b15c85b..d8d2deeb 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__")