diff --git a/CHANGELOG.md b/CHANGELOG.md index 051202a58..f5a8f3ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ ([#6659](https://github.com/mitmproxy/mitmproxy/pull/6659), @basedBaba) * Fix a regression when leaf cert creation would fail with intermediate CAs in `ca_file`. ([#6666](https://github.com/mitmproxy/mitmproxy/pull/6666), @manselmi) +* Add `content_view_lines_cutoff` option to mitmdump + ([#6692](https://github.com/mitmproxy/mitmproxy/pull/6692), @errorxyz) ## 21 January 2024: mitmproxy 10.2.2 diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py index b76c34832..1fdfe8bcf 100644 --- a/mitmproxy/addons/dumper.py +++ b/mitmproxy/addons/dumper.py @@ -18,6 +18,7 @@ from mitmproxy import flowfilter from mitmproxy import http from mitmproxy.contrib import click as miniclick from mitmproxy.net.dns import response_codes +from mitmproxy.options import CONTENT_VIEW_LINES_CUTOFF from mitmproxy.tcp import TCPFlow from mitmproxy.tcp import TCPMessage from mitmproxy.udp import UDPFlow @@ -54,12 +55,12 @@ class Dumper: "flow_detail", int, 1, - """ + f""" The display detail level for flows in mitmdump: 0 (quiet) to 4 (very verbose). 0: no output 1: shortened request URL with response status code 2: full request URL with response status code and HTTP headers - 3: 2 + truncated response content, content of WebSocket and TCP messages + 3: 2 + truncated response content, content of WebSocket and TCP messages (content_view_lines_cutoff: {CONTENT_VIEW_LINES_CUTOFF}) 4: 3 + nothing is truncated """, ) @@ -125,7 +126,9 @@ class Dumper: logging.debug(error) if ctx.options.flow_detail == 3: - lines_to_echo = itertools.islice(lines, 70) + lines_to_echo = itertools.islice( + lines, ctx.options.content_view_lines_cutoff + ) else: lines_to_echo = lines diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index c7f2e85d4..e9b6a92bc 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -97,7 +97,7 @@ def test_simple(): def test_echo_body(): f = tflow.tflow(resp=True) f.response.headers["content-type"] = "text/html" - f.response.content = b"foo bar voing\n" * 100 + f.response.content = b"foo bar voing\n" * 600 sio = io.StringIO() d = dumper.Dumper(sio) @@ -108,6 +108,21 @@ def test_echo_body(): assert "cut off" in t +def test_echo_body_custom_cutoff(): + f = tflow.tflow(resp=True) + f.response.headers["content-type"] = "text/html" + f.response.content = b"foo bar voing\n" * 4 + + sio = io.StringIO() + d = dumper.Dumper(sio) + with taddons.context(d) as ctx: + ctx.configure(d, flow_detail=3) + ctx.configure(d, content_view_lines_cutoff=3) + d._echo_message(f.response, f) + t = sio.getvalue() + assert "cut off" in t + + def test_echo_trailer(): sio = io.StringIO() d = dumper.Dumper(sio) @@ -118,7 +133,7 @@ def test_echo_trailer(): f.request.headers["content-type"] = "text/html" f.request.headers["transfer-encoding"] = "chunked" f.request.headers["trailer"] = "my-little-request-trailer" - f.request.content = b"some request content\n" * 100 + f.request.content = b"some request content\n" * 600 f.request.trailers = Headers( [(b"my-little-request-trailer", b"foobar-request-trailer")] )