aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/flowview.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-12 13:49:16 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-12 13:49:16 +0200
commit049d253a83e18116340670cb86528b4ac1d3b215 (patch)
treed2a6b1db9fd1c98bdc500c3b43158d73b02954cb /libmproxy/console/flowview.py
parent9c31669211dd0b81e3f7f5325a3564e827a8d6d0 (diff)
downloadmitmproxy-049d253a83e18116340670cb86528b4ac1d3b215.tar.gz
mitmproxy-049d253a83e18116340670cb86528b4ac1d3b215.tar.bz2
mitmproxy-049d253a83e18116340670cb86528b4ac1d3b215.zip
simplify contentview api
Diffstat (limited to 'libmproxy/console/flowview.py')
-rw-r--r--libmproxy/console/flowview.py58
1 files changed, 35 insertions, 23 deletions
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 192b1e5b..3e13fab4 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -1,15 +1,15 @@
from __future__ import absolute_import
import os
-import sys
import traceback
+import sys
+
import urwid
from netlib import odict
from netlib.http.semantics import CONTENT_MISSING, Headers
-
from . import common, grideditor, signals, searchable, tabs
from . import flowdetailview
-from .. import utils, controller, contentview
+from .. import utils, controller, contentviews
from ..models import HTTPRequest, HTTPResponse, decoded
from ..exceptions import ContentViewException
@@ -167,10 +167,10 @@ class FlowView(tabs.Tabs):
if flow == self.flow:
self.show()
- def content_view(self, viewmode, conn):
- if conn.content == CONTENT_MISSING:
+ def content_view(self, viewmode, message):
+ if message.body == CONTENT_MISSING:
msg, body = "", [urwid.Text([("error", "[content missing]")])]
- return (msg, body)
+ return msg, body
else:
full = self.state.get_flow_setting(
self.flow,
@@ -180,29 +180,43 @@ class FlowView(tabs.Tabs):
if full:
limit = sys.maxsize
else:
- limit = contentview.VIEW_CUTOFF
+ limit = contentviews.VIEW_CUTOFF
return cache.get(
self._get_content_view,
viewmode,
- conn.headers,
- conn.content,
- limit,
- isinstance(conn, HTTPRequest)
+ message,
+ limit
)
- def _get_content_view(self, viewmode, headers, content, limit, is_request):
+ def _get_content_view(self, viewmode, message, max_lines):
+
try:
- description, lines = contentview.get_content_view(
- viewmode, headers, content, limit, is_request
+ description, lines = contentviews.get_content_view(
+ viewmode, message.body, headers=message.headers
)
except ContentViewException:
s = "Content viewer failed: \n" + traceback.format_exc()
signals.add_event(s, "error")
- description, lines = contentview.get_content_view(
- contentview.get("Raw"), headers, content, limit, is_request
+ description, lines = contentviews.get_content_view(
+ contentviews.get("Raw"), message.body, headers=message.headers
)
description = description.replace("Raw", "Couldn't parse: falling back to Raw")
- text_objects = [urwid.Text(l) for l in lines]
+
+ # Give hint that you have to tab for the response.
+ if description == "No content" and isinstance(message, HTTPRequest):
+ description = "No request content (press tab to view response)"
+
+ text_objects = []
+ for line in lines:
+ text_objects.append(urwid.Text(line))
+ if len(text_objects) == max_lines:
+ text_objects.append(urwid.Text([
+ ("highlight", "Stopped displaying data after %d lines. Press " % max_lines),
+ ("key", "f"),
+ ("highlight", " to load all data.")
+ ]))
+ break
+
return description, text_objects
def viewmode_get(self):
@@ -227,9 +241,7 @@ class FlowView(tabs.Tabs):
[
("heading", msg),
]
- )
- ]
- cols.append(
+ ),
urwid.Text(
[
" ",
@@ -239,7 +251,7 @@ class FlowView(tabs.Tabs):
],
align="right"
)
- )
+ ]
title = urwid.AttrWrap(urwid.Columns(cols), "heading")
txt.append(title)
@@ -471,7 +483,7 @@ class FlowView(tabs.Tabs):
self.state.add_flow_setting(
self.flow,
(self.tab_offset, "prettyview"),
- contentview.get_by_shortcut(t)
+ contentviews.get_by_shortcut(t)
)
signals.flow_change.send(self, flow = self.flow)
@@ -611,7 +623,7 @@ class FlowView(tabs.Tabs):
scope = "s"
common.ask_copy_part(scope, self.flow, self.master, self.state)
elif key == "m":
- p = list(contentview.view_prompts)
+ p = list(contentviews.view_prompts)
p.insert(0, ("Clear", "C"))
signals.status_prompt_onekey.send(
self,