From 1438fc3006166246f29c179873a1aa2300a5af14 Mon Sep 17 00:00:00 2001 From: Hu Bo Date: Thu, 23 Mar 2017 17:36:02 +0800 Subject: [PATCH 1/3] assume multipart/form-data field as text --- aiohttp/web_request.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aiohttp/web_request.py b/aiohttp/web_request.py index 6a4737e7f2e..e82b587574c 100644 --- a/aiohttp/web_request.py +++ b/aiohttp/web_request.py @@ -409,7 +409,8 @@ def post(self): out.add(field.name, ff) else: value = yield from field.read(decode=True) - if content_type.startswith('text/'): + if content_type is None or \ + content_type.startswith('text/'): charset = field.get_charset(default='utf-8') value = value.decode(charset) out.add(field.name, value) From e65091cfe513e84220f6021667c68403c8e754fe Mon Sep 17 00:00:00 2001 From: hubo Date: Thu, 23 Mar 2017 21:51:49 +0800 Subject: [PATCH 2/3] Add unit test --- tests/test_web_request.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_web_request.py b/tests/test_web_request.py index 9149d1da946..34f522b59b4 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -335,6 +335,28 @@ def test_make_too_big_request_adjust_limit(loop): assert len(txt) == 1024**2 + 1 +@asyncio.coroutine +def test_multipart_formdata(loop): + payload = StreamReader(loop=loop) + payload.feed_data(b"""-----------------------------326931944431359\r +Content-Disposition: form-data; name="a"\r +\r +b\r +-----------------------------326931944431359\r +Content-Disposition: form-data; name="c"\r +\r +d\r +-----------------------------326931944431359--\r\n""") + content_type = "multipart/form-data; boundary="\ + "---------------------------326931944431359" + payload.feed_eof() + req = make_mocked_request('POST', '/', + headers={'CONTENT-TYPE': content_type}, + payload=payload) + result = yield from req.post() + assert dict(result) == {'a': 'b', 'c': 'd'} + + @asyncio.coroutine def test_make_too_big_request_limit_None(loop): payload = StreamReader(loop=loop) From 932b2311f48761eb70d3e650fa70ef8d9af6316f Mon Sep 17 00:00:00 2001 From: Hu Bo Date: Sat, 25 Mar 2017 00:15:06 +0800 Subject: [PATCH 3/3] Add "Hu Bo" to contributors --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index b14b4c94fb5..c16001c71b1 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -67,6 +67,7 @@ Georges Dubus Greg Holt Gregory Haynes Günther Jena +Hu Bo Hugo Herter Igor Pavlov Ingmar Steen