Skip to content

Commit

Permalink
Add a test which verifies that ChunkedEncodingError is emitted if an …
Browse files Browse the repository at this point in the history
…invalid Transfer-Encoding: chunked response is returned. (#5906)
  • Loading branch information
theGOTOguy authored Aug 25, 2021
1 parent b0e025a commit 2d30aeb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ def test_chunked_upload():
assert r.request.headers['Transfer-Encoding'] == 'chunked'


def test_chunked_encoding_error():
"""get a ChunkedEncodingError if the server returns a bad response"""

def incomplete_chunked_response_handler(sock):
request_content = consume_socket_content(sock, timeout=0.5)

# The server never ends the request and doesn't provide any valid chunks
sock.send(b"HTTP/1.1 200 OK\r\n" +
b"Transfer-Encoding: chunked\r\n")

return request_content

close_server = threading.Event()
server = Server(incomplete_chunked_response_handler)

with server as (host, port):
url = 'http://{}:{}/'.format(host, port)
with pytest.raises(requests.exceptions.ChunkedEncodingError):
r = requests.get(url)
close_server.set() # release server block


def test_digestauth_401_count_reset_on_redirect():
"""Ensure we correctly reset num_401_calls after a successful digest auth,
followed by a 302 redirect to another digest auth prompt.
Expand Down

0 comments on commit 2d30aeb

Please sign in to comment.