Controls the length of URL displayed using the -d option (#1903)

This commit is contained in:
lymanZerga11 2017-01-05 21:37:20 +08:00 committed by Maximilian Hils
parent 2335a70b79
commit 3ea76a7f3e
2 changed files with 13 additions and 0 deletions

View File

@ -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 = ""

View File

@ -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__")