diff options
| author | Jordan Moldow <jmoldow@box.com> | 2015-07-14 13:14:23 -0700 |
|---|---|---|
| committer | Jordan Moldow <jmoldow@box.com> | 2015-07-14 13:14:23 -0700 |
| commit | 2ac600e43ddd29efa08220333ab7ebe13234ed37 (patch) | |
| tree | 09c87c00bcce4cd1083dc374e63063676dcff010 /test/test_response.py | |
| parent | 21a288be4487040c6e21e27cec025b74d2a83152 (diff) | |
| download | urllib3-2ac600e43ddd29efa08220333ab7ebe13234ed37.tar.gz | |
Make stream() satisfy its v1.10 contract
In 1.10 through 1.10.2, `HTTPResponse.stream()` always called
`HTTPResponse.read()`. This method catches all `HTTPException`
(including `httplib.IncompleteRead`), and re-raises them as
`ProtocolError`.
In 1.10.3 and 1.10.4, `HTTPResponse.stream()` may call
`HTTPResponse.read_chunked()` instead. This method may (via the
`_update_chunk_length()` helper method) raise `httplib.IncompleteRead`.
This exception will not be caught, and will be raised out of the call to
`HTTPResponse.stream()`.
Fix the contract of `HTTPResponse.stream()` by making
`HTTPResponse.read_chunked()` catch the same low-level exceptions that
`HTTPResponse.read()` catches. This is accomplished by refactoring this
try/except logic into a shared context manager.
Fixes #673.
Diffstat (limited to 'test/test_response.py')
| -rw-r--r-- | test/test_response.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/test/test_response.py b/test/test_response.py index 2e2be0ec..47d05213 100644 --- a/test/test_response.py +++ b/test/test_response.py @@ -7,7 +7,7 @@ try: except ImportError: import httplib from urllib3.response import HTTPResponse -from urllib3.exceptions import DecodeError, ResponseNotChunked +from urllib3.exceptions import DecodeError, ResponseNotChunked, ProtocolError from base64 import b64decode @@ -487,7 +487,7 @@ class TestResponse(unittest.TestCase): r.chunked = True r.chunk_left = None resp = HTTPResponse(r, preload_content=False, headers={'transfer-encoding': 'chunked'}) - self.assertRaises(httplib.IncompleteRead, next, resp.read_chunked()) + self.assertRaises(ProtocolError, next, resp.read_chunked()) def test_chunked_response_without_crlf_on_end(self): stream = [b"foo", b"bar", b"baz"] |
