Merge pull request #2610 from colindickson/master

fix contextlib.closing bug for sessions where content is not consumed…
This commit is contained in:
Cory Benfield
2015-05-25 18:15:57 +01:00
3 changed files with 14 additions and 0 deletions
+1
View File
@@ -158,3 +158,4 @@ Patches and Suggestions
- Ulrich Petri (`@ulope <https://github.com/ulope>`_)
- Muhammad Yasoob Ullah Khalid <yasoob.khld@gmail.com> (`@yasoob <https://github.com/yasoob>`_)
- Paul van der Linden (`@pvanderlinden <https://github.com/pvanderlinden>`_)
- Colin Dickson (`@colindickson <https://github.com/colindickson>`_)
+3
View File
@@ -842,4 +842,7 @@ class Response(object):
*Note: Should not normally need to be called explicitly.*
"""
if not self._content_consumed:
return self.raw.close()
return self.raw.release_conn()
+10
View File
@@ -9,6 +9,7 @@ import os
import pickle
import unittest
import collections
import contextlib
import io
import requests
@@ -1060,6 +1061,15 @@ class RequestsTestCase(unittest.TestCase):
next(it)
assert len(list(it)) == 3
def test_unconsumed_session_response_closes_connection(self):
s = requests.session()
with contextlib.closing(s.get(httpbin('stream/4'), stream=True)) as response:
pass
self.assertEqual(response._content_consumed, False)
self.assertTrue(response.raw.closed, True)
@pytest.mark.xfail
def test_response_iter_lines_reentrant(self):
"""Response.iter_lines() is not reentrant safe"""