aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/console')
-rw-r--r--libmproxy/console/common.py4
-rw-r--r--libmproxy/console/contentview.py14
-rw-r--r--libmproxy/console/flowview.py19
3 files changed, 17 insertions, 20 deletions
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py
index c25f7267..ae3dd61e 100644
--- a/libmproxy/console/common.py
+++ b/libmproxy/console/common.py
@@ -415,9 +415,9 @@ def format_flow(f, focus, extended=False, hostheader=False, padding=2,
resp_clen = contentdesc,
roundtrip = roundtrip,
))
- t = f.response.headers["content-type"]
+ t = f.response.headers.get("content-type")
if t:
- d["resp_ctype"] = t[0].split(";")[0]
+ d["resp_ctype"] = t.split(";")[0]
else:
d["resp_ctype"] = ""
return flowcache.get(
diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py
index 95ea7b17..17ed90e1 100644
--- a/libmproxy/console/contentview.py
+++ b/libmproxy/console/contentview.py
@@ -12,7 +12,7 @@ import urwid
import html2text
import netlib.utils
-from netlib import odict, encoding
+from netlib import encoding
from . import common, signals
from .. import utils
@@ -74,7 +74,7 @@ class ViewAuto:
content_types = []
def __call__(self, hdrs, content, limit):
- ctype = hdrs.get_first("content-type")
+ ctype = hdrs.get("content-type")
if ctype:
ct = netlib.utils.parse_content_type(ctype) if ctype else None
ct = "%s/%s" % (ct[0], ct[1])
@@ -508,7 +508,7 @@ def get(name):
return i
-def get_content_view(viewmode, hdrItems, content, limit, is_request):
+def get_content_view(viewmode, headers, content, limit, is_request):
"""
Returns a (msg, body) tuple.
"""
@@ -519,16 +519,14 @@ def get_content_view(viewmode, hdrItems, content, limit, is_request):
return "No content", ""
msg = []
- hdrs = odict.ODictCaseless([list(i) for i in hdrItems])
-
- enc = hdrs.get_first("content-encoding")
+ enc = headers.get("content-encoding")
if enc and enc != "identity":
decoded = encoding.decode(enc, content)
if decoded:
content = decoded
msg.append("[decoded %s]" % enc)
try:
- ret = viewmode(hdrs, content, limit)
+ ret = viewmode(headers, content, limit)
# Third-party viewers can fail in unexpected ways...
except Exception:
s = traceback.format_exc()
@@ -536,7 +534,7 @@ def get_content_view(viewmode, hdrItems, content, limit, is_request):
signals.add_event(s, "error")
ret = None
if not ret:
- ret = get("Raw")(hdrs, content, limit)
+ ret = get("Raw")(headers, content, limit)
msg.append("Couldn't parse: falling back to Raw")
else:
msg.append(ret[0])
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 8b828653..19917555 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -4,7 +4,7 @@ import sys
import urwid
from netlib import odict
-from netlib.http.semantics import CONTENT_MISSING
+from netlib.http.semantics import CONTENT_MISSING, Headers
from . import common, grideditor, contentview, signals, searchable, tabs
from . import flowdetailview
@@ -182,7 +182,7 @@ class FlowView(tabs.Tabs):
description, text_objects = cache.get(
contentview.get_content_view,
viewmode,
- tuple(tuple(i) for i in conn.headers.lst),
+ conn.headers,
conn.content,
limit,
isinstance(conn, HTTPRequest)
@@ -199,7 +199,7 @@ class FlowView(tabs.Tabs):
def conn_text(self, conn):
if conn:
txt = common.format_keyvals(
- [(h + ":", v) for (h, v) in conn.headers.lst],
+ [(h + ":", v) for (h, v) in conn.headers.fields],
key = "header",
val = "text"
)
@@ -284,8 +284,8 @@ class FlowView(tabs.Tabs):
response.msg = msg
signals.flow_change.send(self, flow = self.flow)
- def set_headers(self, lst, conn):
- conn.headers = odict.ODictCaseless(lst)
+ def set_headers(self, fields, conn):
+ conn.headers = Headers(fields)
signals.flow_change.send(self, flow = self.flow)
def set_query(self, lst, conn):
@@ -330,7 +330,7 @@ class FlowView(tabs.Tabs):
if not self.flow.response:
self.flow.response = HTTPResponse(
self.flow.request.httpversion,
- 200, "OK", odict.ODictCaseless(), ""
+ 200, "OK", Headers(), ""
)
self.flow.response.reply = controller.DummyReply()
message = self.flow.response
@@ -381,7 +381,7 @@ class FlowView(tabs.Tabs):
self.master.view_grideditor(
grideditor.HeaderEditor(
self.master,
- message.headers.lst,
+ message.headers.fields,
self.set_headers,
message
)
@@ -616,8 +616,7 @@ class FlowView(tabs.Tabs):
key = None
elif key == "v":
if conn.content:
- t = conn.headers["content-type"] or [None]
- t = t[0]
+ t = conn.headers.get("content-type")
if "EDITOR" in os.environ or "PAGER" in os.environ:
self.master.spawn_external_viewer(conn.content, t)
else:
@@ -626,7 +625,7 @@ class FlowView(tabs.Tabs):
)
elif key == "z":
self.flow.backup()
- e = conn.headers.get_first("content-encoding", "identity")
+ e = conn.headers.get("content-encoding", "identity")
if e != "identity":
if not conn.decode():
signals.status_message.send(