Skip to content

Commit

Permalink
response.text returns None if response.body is None
Browse files Browse the repository at this point in the history
  • Loading branch information
jettify committed Jun 25, 2015
1 parent fc0a1c0 commit 4284bed
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 4284bed

Please sign in to comment.