Skip to content

Commit

Permalink
Preserved chunker transfer on broken connections
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Nov 5, 2019
1 parent 0019edd commit 8709bd5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/urllib3/connectionpool.py
Expand Up @@ -755,6 +755,7 @@ def urlopen(
timeout=timeout,
pool_timeout=pool_timeout,
release_conn=release_conn,
chunked=chunked,
body_pos=body_pos,
**response_kw
)
Expand Down
25 changes: 25 additions & 0 deletions test/with_dummyserver/test_chunked_transfer.py
Expand Up @@ -149,3 +149,28 @@ def socket_handler(listener):
"GET", "/", chunked=True, preload_content=False, retries=retries
)
assert self.chunked_requests == 2

def test_preserve_chunked_on_broken_connection(self):
self.chunked_requests = 0

def socket_handler(listener):
for i in range(2):
sock = listener.accept()[0]
request = consume_socket(sock)
if b"Transfer-Encoding: chunked" in request.split(b"\r\n"):
self.chunked_requests += 1

if i == 0:
# Bad HTTP version will trigger a connection close
sock.send(b"HTTP/0.5 200 OK\r\n\r\n")
else:
sock.send(b"HTTP/1.1 200 OK\r\n\r\n")
sock.close()

self._start_server(socket_handler)
with HTTPConnectionPool(self.host, self.port) as pool:
retries = Retry(read=1)
pool.urlopen(
"GET", "/", chunked=True, preload_content=False, retries=retries
)
assert self.chunked_requests == 2

0 comments on commit 8709bd5

Please sign in to comment.