Truncate URLs in console

This commit is contained in:
Shadab Zafar 2016-08-20 14:52:22 +05:30
parent cacee3871c
commit 22283dd373
2 changed files with 15 additions and 3 deletions

View File

@ -32,6 +32,8 @@ METHOD_OPTIONS = [
("edit raw", "e"), ("edit raw", "e"),
] ]
MAX_URL_LEN = 200
def is_keypress(k): def is_keypress(k):
""" """
@ -328,7 +330,7 @@ def export_to_clip_or_file(key, scope, flow, writer):
flowcache = utils.LRUCache(800) flowcache = utils.LRUCache(800)
def raw_format_flow(f, focus, extended): def raw_format_flow(f, focus, extended, short_urls):
f = dict(f) f = dict(f)
pile = [] pile = []
req = [] req = []
@ -359,6 +361,11 @@ def raw_format_flow(f, focus, extended):
uc = "title" uc = "title"
url = f["req_url"] 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"): if f["req_http_version"] not in ("HTTP/1.0", "HTTP/1.1"):
url += " " + f["req_http_version"] url += " " + f["req_http_version"]
req.append( req.append(
@ -410,7 +417,7 @@ def raw_format_flow(f, focus, extended):
return urwid.Pile(pile) 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( d = dict(
intercepted = f.intercepted, intercepted = f.intercepted,
acked = f.reply.state == "committed", acked = f.reply.state == "committed",
@ -451,5 +458,8 @@ def format_flow(f, focus, extended=False, hostheader=False):
d["resp_ctype"] = "" d["resp_ctype"] = ""
return flowcache.get( return flowcache.get(
raw_format_flow, raw_format_flow,
tuple(sorted(d.items())), focus, extended tuple(sorted(d.items())),
focus,
extended,
short_urls,
) )

View File

@ -108,6 +108,7 @@ class FlowViewHeader(urwid.WidgetWrap):
f, f,
False, False,
extended=True, extended=True,
short_urls=False,
hostheader=self.master.options.showhost hostheader=self.master.options.showhost
) )
signals.flow_change.connect(self.sig_flow_change) signals.flow_change.connect(self.sig_flow_change)
@ -118,6 +119,7 @@ class FlowViewHeader(urwid.WidgetWrap):
flow, flow,
False, False,
extended=True, extended=True,
short_urls=False,
hostheader=self.master.options.showhost hostheader=self.master.options.showhost
) )