diff options
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/console/connview.py | 5 | ||||
-rw-r--r-- | libmproxy/flow.py | 23 |
2 files changed, 24 insertions, 4 deletions
diff --git a/libmproxy/console/connview.py b/libmproxy/console/connview.py index b15f0c8f..38fecfa0 100644 --- a/libmproxy/console/connview.py +++ b/libmproxy/console/connview.py @@ -176,7 +176,7 @@ class ConnectionView(common.WWrap): if i[0].lower() == "content-type": ctype = i[1] break - if ctype and "x-www-form-urlencoded" in ctype: + if ctype and flow.HDR_FORM_URLENCODED in ctype: data = utils.urldecode(content) if data: return self._view_conn_urlencoded(data) @@ -221,9 +221,6 @@ class ConnectionView(common.WWrap): txt.extend(self._view_conn_raw(content)) return urwid.ListBox(txt) - - - def _tab(self, content, active): if active: attr = "heading" diff --git a/libmproxy/flow.py b/libmproxy/flow.py index e929440e..85c48ce1 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -8,6 +8,8 @@ import tnetstring, filt, script, utils, encoding, proxy from email.utils import parsedate_tz, formatdate, mktime_tz import controller, version +HDR_FORM_URLENCODED = "x-www-form-urlencoded" + class RunException(Exception): def __init__(self, msg, returncode, errout): Exception.__init__(self, msg) @@ -56,6 +58,8 @@ class Headers: return new def __setitem__(self, k, hdrs): + if isinstance(hdrs, basestring): + raise ValueError("Header values should be lists.") k = self._kconv(k) new = self._filter_lst(k, self.lst) for i in hdrs: @@ -312,6 +316,25 @@ class Request(HTTPMsg): host = "%s:%s"%(self.host, self.port) return host + def get_form_urlencoded(self): + """ + Retrieves the URL-encoded form data, returning a list of (key, + value) tuples. Returns an empty list if there is no data or the + content-type indicates non-form data. + """ + hv = [i.lower() for i in self.headers["content-type"]] + if HDR_FORM_URLENCODED in hv: + return utils.urldecode(self.content) + return [] + + def set_form_urlencoded(self, data): + """ + Sets the body to the URL-encoded form data, and adds the + appropriate content-type header. + """ + self.headers["content-type"] = [HDR_FORM_URLENCODED] + self.content = utils.urlencode(data) + def get_query(self): """ Gets the request query string. Returns a list of (key, value) |