From 595d2a2fa09ea8c16507266a0c4d435bb1c68983 Mon Sep 17 00:00:00 2001 From: Will Coster Date: Tue, 16 Feb 2016 18:35:42 -0800 Subject: Add a content view for query parameters The query content view uses format_dict to display a table of query parameters and is made the default content view for requests with query parameters and no request body. To facilitate this the query parameter dictionary of HTTPRequests is added to the metadata content view parameter under the "query" key. Additionally, the logic for handling "no content" messages is moved from contentviews.get_content_view to ViewAuto. This is necessary as it allows the query content view to be displayed when there is no request body. --- test/mitmproxy/test_contentview.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index 7f1d735e..c00afa5f 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -1,5 +1,6 @@ from mitmproxy.exceptions import ContentViewException from netlib.http import Headers +from netlib.odict import ODict import netlib.utils from netlib import encoding @@ -45,6 +46,19 @@ class TestContentView: ) assert f[0].startswith("XML") + f = v( + "", + headers=Headers() + ) + assert f[0] == "No content" + + f = v( + "", + headers=Headers(), + query=ODict([("foo", "bar")]), + ) + assert f[0] == "Query" + def test_view_urlencoded(self): d = netlib.utils.urlencode([("one", "two"), ("three", "four")]) v = cv.ViewURLEncoded() @@ -158,6 +172,13 @@ Larry h = Headers(content_type="unparseable") assert not view(v, headers=h) + def test_view_query(self): + d = "" + v = cv.ViewQuery() + f = v(d, query=ODict([("foo", "bar")])) + assert f[0] == "Query" + assert [x for x in f[1]] == [[("header", "foo: "), ("text", "bar")]] + def test_get_content_view(self): r = cv.get_content_view( cv.get("Raw"), -- cgit v1.2.3