mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user