Skip to content

Commit

Permalink
Add timeout to stream with testing
Browse files Browse the repository at this point in the history
Fixes Issue #1803
  • Loading branch information
cjstapleton committed Feb 28, 2014
1 parent e909a92 commit 930f03c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox

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:
Expand Down
9 changes: 9 additions & 0 deletions test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,15 @@ def test_max_age_invalid_str(self):
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()


0 comments on commit 930f03c

Please sign in to comment.