Skip to content

Commit

Permalink
Merge pull request #420 from jettify/fix-response-text
Browse files Browse the repository at this point in the history
fix response.text property
  • Loading branch information
asvetlov committed Jun 25, 2015
2 parents c960404 + 4284bed commit 4da27ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ def body(self, body):

@property
def text(self):
if self._body is None:
return None
return self._body.decode(self.charset or 'utf-8')

@text.setter
Expand Down
5 changes: 5 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,8 @@ def test_text_in_ctor_with_content_type_header(self):
self.assertEqual('текст'.encode('koi8-r'), resp.body)
self.assertEqual('text/html', resp.content_type)
self.assertEqual('koi8-r', resp.charset)

def test_text_with_empty_payload(self):
resp = Response(status=200)
self.assertEqual(resp.body, None)
self.assertEqual(resp.text, None)

0 comments on commit 4da27ce

Please sign in to comment.