mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2610 from colindickson/master
fix contextlib.closing bug for sessions where content is not consumed…
This commit is contained in:
@@ -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>`_)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user