Skip to content

Commit

Permalink
Test that chunked=True is preserved on retries
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Oct 29, 2019
1 parent f7edf72 commit 7d2419b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/with_dummyserver/test_chunked_transfer.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-

from urllib3 import HTTPConnectionPool
from dummyserver.testcase import SocketDummyServerTestCase
from urllib3.util.retry import Retry
from dummyserver.testcase import SocketDummyServerTestCase, consume_socket


class TestChunkedTransfer(SocketDummyServerTestCase):
Expand Down Expand Up @@ -100,3 +101,24 @@ def test_provides_default_host_header(self):

host_headers = [x for x in header_lines if x.startswith(b"host")]
assert len(host_headers) == 1

def test_preserve_chunked_on_retry(self):
self.chunked_requests = 0

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

sock.send(b"HTTP/1.1 404 Not Found\r\n\r\n")
sock.close()

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

0 comments on commit 7d2419b

Please sign in to comment.