Skip to content

Commit

Permalink
add charset to url endoded string #1750
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 27, 2017
1 parent 1a788c5 commit 1ad0393
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aiohttp/formdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
27 changes: 27 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1ad0393

Please sign in to comment.