From 22283dd37346dcc62a68e9a1c520638cbbbfa869 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Sat, 20 Aug 2016 14:52:22 +0530 Subject: Truncate URLs in console --- mitmproxy/console/common.py | 16 +++++++++++++--- mitmproxy/console/flowview.py | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mitmproxy/console/common.py b/mitmproxy/console/common.py index 5a24e789..b514e43f 100644 --- a/mitmproxy/console/common.py +++ b/mitmproxy/console/common.py @@ -32,6 +32,8 @@ METHOD_OPTIONS = [ ("edit raw", "e"), ] +MAX_URL_LEN = 200 + def is_keypress(k): """ @@ -328,7 +330,7 @@ def export_to_clip_or_file(key, scope, flow, writer): flowcache = utils.LRUCache(800) -def raw_format_flow(f, focus, extended): +def raw_format_flow(f, focus, extended, short_urls): f = dict(f) pile = [] req = [] @@ -359,6 +361,11 @@ def raw_format_flow(f, focus, extended): uc = "title" url = f["req_url"] + + # TODO: Add a configuration setting that disables this behaviour? + if short_urls and len(url) > MAX_URL_LEN: + url = url[:MAX_URL_LEN] + "..." + if f["req_http_version"] not in ("HTTP/1.0", "HTTP/1.1"): url += " " + f["req_http_version"] req.append( @@ -410,7 +417,7 @@ def raw_format_flow(f, focus, extended): return urwid.Pile(pile) -def format_flow(f, focus, extended=False, hostheader=False): +def format_flow(f, focus, extended=False, hostheader=False, short_urls=True): d = dict( intercepted = f.intercepted, acked = f.reply.state == "committed", @@ -451,5 +458,8 @@ def format_flow(f, focus, extended=False, hostheader=False): d["resp_ctype"] = "" return flowcache.get( raw_format_flow, - tuple(sorted(d.items())), focus, extended + tuple(sorted(d.items())), + focus, + extended, + short_urls, ) diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py index 6d74be65..0f54c7cb 100644 --- a/mitmproxy/console/flowview.py +++ b/mitmproxy/console/flowview.py @@ -108,6 +108,7 @@ class FlowViewHeader(urwid.WidgetWrap): f, False, extended=True, + short_urls=False, hostheader=self.master.options.showhost ) signals.flow_change.connect(self.sig_flow_change) @@ -118,6 +119,7 @@ class FlowViewHeader(urwid.WidgetWrap): flow, False, extended=True, + short_urls=False, hostheader=self.master.options.showhost ) -- cgit v1.2.3