diff options
-rw-r--r-- | libmproxy/console/connview.py | 4 | ||||
-rw-r--r-- | libmproxy/flow.py | 27 | ||||
-rw-r--r-- | test/test_flow.py | 6 |
3 files changed, 18 insertions, 19 deletions
diff --git a/libmproxy/console/connview.py b/libmproxy/console/connview.py index 7bdf75bd..2bf6a4af 100644 --- a/libmproxy/console/connview.py +++ b/libmproxy/console/connview.py @@ -377,7 +377,7 @@ class ConnectionView(common.WWrap): conn.set_query(flow.ODict(lst)) def set_form(self, lst, conn): - conn.set_form_urlencoded(lst) + conn.set_form_urlencoded(flow.ODict(lst)) def edit(self, part): if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: @@ -392,7 +392,7 @@ class ConnectionView(common.WWrap): c = self.master.spawn_editor(conn.content or "") conn.content = c.rstrip("\n") elif part == "f": - self.master.view_kveditor("Editing form", conn.get_form_urlencoded(), self.set_form, conn) + self.master.view_kveditor("Editing form", conn.get_form_urlencoded().lst, self.set_form, conn) elif part == "h": self.master.view_kveditor("Editing headers", conn.headers.lst, self.set_headers, conn) elif part == "q": diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 0ca4d262..6678771f 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -301,40 +301,39 @@ class Request(HTTPMsg): 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. + Retrieves the URL-encoded form data, returning an ODict object. + Returns an empty ODict 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 [] + return ODict(utils.urldecode(self.content)) + return ODict([]) - def set_form_urlencoded(self, data): + def set_form_urlencoded(self, odict): """ Sets the body to the URL-encoded form data, and adds the - appropriate content-type header. + appropriate content-type header. Note that this will destory the + existing body if there is one. """ self.headers["Content-Type"] = [HDR_FORM_URLENCODED] - self.content = utils.urlencode(data) + self.content = utils.urlencode(odict.lst) def get_query(self): """ - Gets the request query string. Returns a list of (key, value) - tuples. + Gets the request query string. Returns an ODict object. """ _, _, _, _, query, _ = urlparse.urlparse(self.get_url()) if not query: return [] return ODict(utils.urldecode(query)) - def set_query(self, q): + def set_query(self, odict): """ - Takes a list of (key, value) tuples, and sets the request query - string. + Takes an ODict object, and sets the request query string. """ scheme, netloc, path, params, _, fragment = urlparse.urlparse(self.get_url()) - query = utils.urlencode(q.lst) + query = utils.urlencode(odict.lst) self.set_url(urlparse.urlunparse([scheme, netloc, path, params, query, fragment])) def get_url(self): diff --git a/test/test_flow.py b/test/test_flow.py index 4cbd5e73..7ca489c6 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -641,11 +641,11 @@ class uRequest(libpry.AutoTree): def test_getset_form_urlencoded(self): h = flow.ODict() h["content-type"] = [flow.HDR_FORM_URLENCODED] - d = [("one", "two"), ("three", "four")] - r = flow.Request(None, "host", 22, "https", "GET", "/", h, utils.urlencode(d)) + d = flow.ODict([("one", "two"), ("three", "four")]) + r = flow.Request(None, "host", 22, "https", "GET", "/", h, utils.urlencode(d.lst)) assert r.get_form_urlencoded() == d - d = [("x", "y")] + d = flow.ODict([("x", "y")]) r.set_form_urlencoded(d) assert r.get_form_urlencoded() == d |