Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KeepSafe/aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 27, 2016
2 parents 702dd0a + 5893901 commit 3e6cbd4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CHANGES

- Added option on `StaticRoute` to follow symlinks #1299

-
- Force encoding of `application/json` content type to utf-8 #1339

-

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Julien Duponchelle
Junjie Tao
Justas Trimailovas
Kay Zheng
Kimmo Parviainen-Jalanko
Kirill Klenov
Kirill Malovitsa
Kyrylo Perevozchikov
Expand Down
6 changes: 5 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,11 @@ def _get_encoding(self):

encoding = params.get('charset')
if not encoding:
encoding = chardet.detect(self._content)['encoding']
if mtype == 'application' and stype == 'json':
# RFC 7159 states that the default encoding is UTF-8.
encoding = 'utf-8'
else:
encoding = chardet.detect(self._content)['encoding']
if not encoding:
encoding = 'utf-8'

Expand Down
2 changes: 1 addition & 1 deletion docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ like one using :meth:`Request.copy`.
Returns :class:`~multidict.MultiDictProxy` instance filled
with parsed data.

If :attr:`method` is not *POST*, *PUT* or *PATCH* or
If :attr:`method` is not *POST*, *PUT*, *PATCH*, *TRACE* or *DELETE* or
:attr:`content_type` is not empty or
*application/x-www-form-urlencoded* or *multipart/form-data*
returns empty multidict.
Expand Down
2 changes: 1 addition & 1 deletion requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pyflakes==1.3.0
coverage==4.2
cchardet==1.1.0
sphinx==1.4.8
cython==0.25
cython==0.25.1
chardet==2.3.0
isort==4.2.5
tox==2.4.1
Expand Down
2 changes: 1 addition & 1 deletion requirements-wheel.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cython==0.25
cython==0.25.1
pytest==3.0.3

21 changes: 1 addition & 20 deletions tests/test_client_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def side_effect(*args, **kwargs):
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut

response.headers = {'Content-Type': 'application/json'}
response.headers = {'Content-Type': 'text/plain'}
content = response.content = mock.Mock()
content.read.side_effect = side_effect

Expand Down Expand Up @@ -275,25 +275,6 @@ def side_effect(*args, **kwargs):
assert not response._get_encoding.called


@asyncio.coroutine
def test_json_detect_encoding(loop):
response = ClientResponse('get', URL('http://def-cl-resp.org'))
response._post_init(loop)

def side_effect(*args, **kwargs):
fut = helpers.create_future(loop)
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut

response.headers = {'Content-Type': 'application/json'}
content = response.content = mock.Mock()
content.read.side_effect = side_effect

res = yield from response.json()
assert res == {'тест': 'пройден'}
assert response._connection is None


def test_override_flow_control(loop):
class MyResponse(ClientResponse):
flow_control_class = aiohttp.StreamReader
Expand Down

0 comments on commit 3e6cbd4

Please sign in to comment.