diff options
author | Thomas Kriechbaumer <Kriechi@users.noreply.github.com> | 2016-08-26 16:44:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-26 16:44:44 +0200 |
commit | 6afbfc85266e783b1bad432ae1f6715bfb16a39f (patch) | |
tree | 0f1ebedf9666d990a8202cf3fb40ef00d3739f80 | |
parent | af0a58256a19dec697fa5c62cd92189407656ab3 (diff) | |
parent | 2e48f9c3457b6a2e9ccdbb1ef2b52ef44290ef6e (diff) | |
download | mitmproxy-6afbfc85266e783b1bad432ae1f6715bfb16a39f.tar.gz mitmproxy-6afbfc85266e783b1bad432ae1f6715bfb16a39f.tar.bz2 mitmproxy-6afbfc85266e783b1bad432ae1f6715bfb16a39f.zip |
Merge pull request #1493 from dufferzafar/long-urls
Truncate URLs in console
-rw-r--r-- | mitmproxy/console/common.py | 26 | ||||
-rw-r--r-- | mitmproxy/console/flowlist.py | 4 |
2 files changed, 20 insertions, 10 deletions
diff --git a/mitmproxy/console/common.py b/mitmproxy/console/common.py index 5a24e789..25181cb7 100644 --- a/mitmproxy/console/common.py +++ b/mitmproxy/console/common.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import absolute_import, print_function, division import os @@ -328,11 +330,11 @@ 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): f = dict(f) pile = [] req = [] - if extended: + if f["extended"]: req.append( fcol( human.format_timestamp(f["req_timestamp"]), @@ -340,7 +342,7 @@ def raw_format_flow(f, focus, extended): ) ) else: - req.append(fcol(">>" if focus else " ", "focus")) + req.append(fcol(">>" if f["focus"] else " ", "focus")) if f["marked"]: req.append(fcol(SYMBOL_MARK, "mark")) @@ -359,6 +361,10 @@ def raw_format_flow(f, focus, extended): uc = "title" url = f["req_url"] + + if f["max_url_len"] and len(url) > f["max_url_len"]: + url = url[:f["max_url_len"]] + "…" + if f["req_http_version"] not in ("HTTP/1.0", "HTTP/1.1"): url += " " + f["req_http_version"] req.append( @@ -384,7 +390,7 @@ def raw_format_flow(f, focus, extended): if f["resp_is_replay"]: resp.append(fcol(SYMBOL_REPLAY, "replay")) resp.append(fcol(f["resp_code"], ccol)) - if extended: + if f["extended"]: resp.append(fcol(f["resp_reason"], ccol)) if f["intercepted"] and f["resp_code"] and not f["acked"]: rc = "intercept" @@ -410,8 +416,12 @@ 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, max_url_len=False): d = dict( + focus=focus, + extended=extended, + max_url_len=max_url_len, + intercepted = f.intercepted, acked = f.reply.state == "committed", @@ -449,7 +459,5 @@ def format_flow(f, focus, extended=False, hostheader=False): d["resp_ctype"] = t.split(";")[0] else: d["resp_ctype"] = "" - return flowcache.get( - raw_format_flow, - tuple(sorted(d.items())), focus, extended - ) + + return flowcache.get(raw_format_flow, tuple(sorted(d.items()))) diff --git a/mitmproxy/console/flowlist.py b/mitmproxy/console/flowlist.py index 7e69e098..11e8fc99 100644 --- a/mitmproxy/console/flowlist.py +++ b/mitmproxy/console/flowlist.py @@ -116,10 +116,12 @@ class ConnectionItem(urwid.WidgetWrap): urwid.WidgetWrap.__init__(self, w) def get_text(self): + cols, _ = self.master.ui.get_cols_rows() return common.format_flow( self.flow, self.f, - hostheader = self.master.options.showhost, + hostheader=self.master.options.showhost, + max_url_len=cols, ) def selectable(self): |