From 973a7b1cd0066046ac5ed633d92f01518239a147 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Thu, 8 Sep 2016 12:40:19 -0600 Subject: [PATCH] test responses fail with incomplete body reads --- tests/test_lowlevel.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_lowlevel.py b/tests/test_lowlevel.py index 126a3a3f..c17ba658 100644 --- a/tests/test_lowlevel.py +++ b/tests/test_lowlevel.py @@ -24,6 +24,23 @@ def test_chunked_upload(): assert r.status_code == 200 assert r.request.headers['Transfer-Encoding'] == 'chunked' +def test_incorrect_content_length(): + """Test ConnectionError raised for incomplete responses""" + close_server = threading.Event() + server = Server.text_response_server( + "HTTP/1.1 200 OK\r\n" + + "Content-Length: 50\r\n\r\n" + + "Hello World." + ) + with server as (host, port): + url = 'http://{0}:{1}/'.format(host, port) + r = requests.Request('GET', url).prepare() + s = requests.Session() + with pytest.raises(requests.exceptions.ConnectionError) as e: + resp = s.send(r) + assert "12 bytes read, 38 more expected" in str(e) + close_server.set() # release server block + _schemes_by_var_prefix = [ ('http', ['http']),