From 7d7e9966596765af8dc3c6c8a709a51f8972d2e6 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 27 Mar 2017 09:36:47 -0700 Subject: [PATCH] add charset to url endoded string #1750 --- aiohttp/formdata.py | 3 ++- tests/test_client_functional.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/aiohttp/formdata.py b/aiohttp/formdata.py index 2a141dc6bf5..f001ec3633b 100644 --- a/aiohttp/formdata.py +++ b/aiohttp/formdata.py @@ -97,7 +97,8 @@ def _gen_form_urlencoded(self): charset = self._charset if self._charset is not None else 'utf-8' return payload.BytesPayload( urlencode(data, doseq=True, encoding=charset).encode(), - content_type='application/x-www-form-urlencoded') + content_type=('application/x-www-form-urlencoded; ' + 'charset=%s' % charset)) def _gen_form_data(self): """Encode a list of fields using the multipart/form-data MIME format""" diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 1627836045a..add48352063 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -1095,6 +1095,30 @@ def handler(request): resp.close() +@asyncio.coroutine +def test_POST_DATA_formdats_with_charset(loop, test_client): + @asyncio.coroutine + def handler(request): + mp = yield from request.post() + assert 'name' in mp + from pprint import pprint + pprint(dict(request.headers)) + return web.Response(text=mp['name']) + + app = web.Application() + app.router.add_post('/', handler) + client = yield from test_client(app) + + form = aiohttp.FormData(charset='koi8-r') + form.add_field('name', 'текст') + + resp = yield from client.post('/', data=form) + assert 200 == resp.status + content = yield from resp.text() + assert content == 'текст' + resp.close() + + @asyncio.coroutine def test_POST_DATA_with_charset_post(loop, test_client): @asyncio.coroutine @@ -1347,6 +1371,9 @@ def handler(request): assert request.content_type in ['application/pgp-keys', 'text/plain', 'application/octet-stream'] + assert request.headers['content-disposition'] == ( + "inline; filename=\"sample.key\"; filename*=utf-8''sample.key") + return web.HTTPOk() app = web.Application()