mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Make Response.content return None if raw is None
Add test.
This commit is contained in:
+1
-1
@@ -769,7 +769,7 @@ class Response(object):
|
||||
raise RuntimeError(
|
||||
'The content for this response was already consumed')
|
||||
|
||||
if not self.status_code:
|
||||
if self.status_code == 0 or self.raw is None:
|
||||
self._content = None
|
||||
else:
|
||||
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
|
||||
|
||||
@@ -1094,6 +1094,10 @@ class TestRequests:
|
||||
total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
|
||||
assert total_seconds > 0.0
|
||||
|
||||
def test_empty_response_has_content_none(self):
|
||||
r = requests.Response()
|
||||
assert r.content is None
|
||||
|
||||
def test_response_is_iterable(self):
|
||||
r = requests.Response()
|
||||
io = StringIO.StringIO('abc')
|
||||
|
||||
Reference in New Issue
Block a user