From e82641ee2d4287a0c422956e28c858b7877cfe01 Mon Sep 17 00:00:00 2001 From: kira0204 Date: Thu, 15 Feb 2018 08:40:54 +0530 Subject: fix 2794 --- mitmproxy/net/http/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/net/http/request.py b/mitmproxy/net/http/request.py index 6b4041f6..9eb98946 100644 --- a/mitmproxy/net/http/request.py +++ b/mitmproxy/net/http/request.py @@ -441,7 +441,7 @@ class Request(message.Message): This will overwrite the existing content if there is one. """ self.headers["content-type"] = "application/x-www-form-urlencoded" - self.content = mitmproxy.net.http.url.encode(form_data, self.content.decode()).encode() + self.content = mitmproxy.net.http.url.encode(form_data, self.get_text(strict=False)).encode() @property def urlencoded_form(self): -- cgit v1.2.3 From 60cd8cb0b10d1e7737d1d1da4a5c65481d94416c Mon Sep 17 00:00:00 2001 From: kira0204 Date: Fri, 16 Feb 2018 22:30:29 +0530 Subject: Adding test --- test/mitmproxy/net/http/test_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index ce49002c..3653d050 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -354,7 +354,7 @@ class TestRequestUtils: assert len(request.urlencoded_form) == 0 def test_set_urlencoded_form(self): - request = treq() + request = treq(content=b"\xec\xed") request.urlencoded_form = [('foo', 'bar'), ('rab', 'oof')] assert request.headers["Content-Type"] == "application/x-www-form-urlencoded" assert request.content -- cgit v1.2.3 From a519afb9c92715880e5be91ffedc1d9f4e7ce904 Mon Sep 17 00:00:00 2001 From: kira0204 Date: Mon, 19 Feb 2018 11:10:19 +0530 Subject: Fixing getter --- mitmproxy/net/http/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/net/http/request.py b/mitmproxy/net/http/request.py index 9eb98946..4ef6cceb 100644 --- a/mitmproxy/net/http/request.py +++ b/mitmproxy/net/http/request.py @@ -430,7 +430,7 @@ class Request(message.Message): is_valid_content_type = "application/x-www-form-urlencoded" in self.headers.get("content-type", "").lower() if is_valid_content_type: try: - return tuple(mitmproxy.net.http.url.decode(self.content.decode())) + return tuple(mitmproxy.net.http.url.decode(self.get_text(strict=False))) except ValueError: pass return () -- cgit v1.2.3 From fb54bb377763b4e57c1a092610d83a2b9ac4e6e9 Mon Sep 17 00:00:00 2001 From: kira0204 Date: Mon, 19 Feb 2018 22:45:30 +0530 Subject: Testing --- mitmproxy/net/http/request.py | 5 +---- test/mitmproxy/net/http/test_request.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/mitmproxy/net/http/request.py b/mitmproxy/net/http/request.py index 4ef6cceb..959fdd33 100644 --- a/mitmproxy/net/http/request.py +++ b/mitmproxy/net/http/request.py @@ -429,10 +429,7 @@ class Request(message.Message): def _get_urlencoded_form(self): is_valid_content_type = "application/x-www-form-urlencoded" in self.headers.get("content-type", "").lower() if is_valid_content_type: - try: - return tuple(mitmproxy.net.http.url.decode(self.get_text(strict=False))) - except ValueError: - pass + return tuple(mitmproxy.net.http.url.decode(self.get_text(strict=False))) return () def _set_urlencoded_form(self, form_data): diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index 3653d050..ef581a91 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -351,7 +351,7 @@ class TestRequestUtils: request.headers["Content-Type"] = "application/x-www-form-urlencoded" assert list(request.urlencoded_form.items()) == [("foobar", "baz")] request.raw_content = b"\xFF" - assert len(request.urlencoded_form) == 0 + assert len(request.urlencoded_form) == 1 def test_set_urlencoded_form(self): request = treq(content=b"\xec\xed") -- cgit v1.2.3