Add timeout to stream with testing

Fixes Issue #1803
This commit is contained in:
cjstapleton
2014-02-28 10:08:57 -06:00
parent e909a92343
commit 930f03c864
2 changed files with 10 additions and 4 deletions
+1 -4
View File
@@ -310,10 +310,7 @@ class HTTPAdapter(BaseAdapter):
chunked = not (request.body is None or 'Content-Length' in request.headers)
if stream:
timeout = TimeoutSauce(connect=timeout)
else:
timeout = TimeoutSauce(connect=timeout, read=timeout)
timeout = TimeoutSauce(connect=timeout, read=timeout)
try:
if not chunked:
+9
View File
@@ -1170,6 +1170,15 @@ class TestMorselToCookieMaxAge(unittest.TestCase):
with pytest.raises(TypeError):
morsel_to_cookie(morsel)
class TestTimeout:
def test_stream_timeout(self):
try:
r = requests.get('https://httpbin.org/delay/10', timeout=5.0)
except requests.exceptions.Timeout as e:
assert 'Read timed out' in e.args[0].args[0]
if __name__ == '__main__':
unittest.main()