Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more than

100 headers are read.  Adapted from patch by Jyrki Pulliainen.
This commit is contained in:
Georg Brandl 2013-10-27 07:34:48 +01:00
parent 28e78414f9
commit bf3f8eb960
4 changed files with 17 additions and 1 deletions

View file

@ -345,6 +345,15 @@ class BasicTest(TestCase):
self.fail("Did not expect response from HEAD request")
self.assertEqual(bytes(b), b'\x00'*5)
def test_too_many_headers(self):
headers = '\r\n'.join('Header%d: foo' % i
for i in range(client._MAXHEADERS + 1)) + '\r\n'
text = ('HTTP/1.1 200 OK\r\n' + headers)
s = FakeSocket(text)
r = client.HTTPResponse(s)
self.assertRaisesRegex(client.HTTPException,
r"got more than \d+ headers", r.begin)
def test_send_file(self):
expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n'
b'Accept-Encoding: identity\r\nContent-Length:')