mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
fix contextlib.closing bug for sessions where content is not consumed (issue #2593)
This commit is contained in:
@@ -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,8 @@ import os
|
||||
import pickle
|
||||
import unittest
|
||||
import collections
|
||||
import contextlib
|
||||
import random
|
||||
|
||||
import io
|
||||
import requests
|
||||
@@ -1252,6 +1254,27 @@ class TestCaseInsensitiveDict(unittest.TestCase):
|
||||
assert frozenset(cid) == keyset
|
||||
|
||||
|
||||
class TestSessionContextClosing(unittest.TestCase):
|
||||
|
||||
def _perform_session_without_consuming(self):
|
||||
session = requests.Session()
|
||||
|
||||
urls = [
|
||||
'http://reddit.com',
|
||||
'http://github.com',
|
||||
'http://bitbucket.org',
|
||||
]
|
||||
|
||||
for _ in range(25):
|
||||
with contextlib.closing(session.get(random.choice(urls), stream=True)) as r:
|
||||
pass
|
||||
|
||||
return "OK"
|
||||
|
||||
def test_stream_session_content_not_consumed(self):
|
||||
self.assertEqual(self._perform_session_without_consuming(), "OK")
|
||||
|
||||
|
||||
class UtilsTestCase(unittest.TestCase):
|
||||
|
||||
def test_super_len_io_streams(self):
|
||||
|
||||
Reference in New Issue
Block a user