mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Fix Issue6791 - Limit the HTTP header readline with _MAXLENGTH. Patch by Antoine Pitrou
This commit is contained in:
parent
32e1771daf
commit
5466bf1c94
4 changed files with 67 additions and 8 deletions
|
@ -317,6 +317,33 @@ class BasicTest(TestCase):
|
|||
self.assertEqual("Basic realm=\"example\"",
|
||||
resp.getheader("www-authenticate"))
|
||||
|
||||
# Test lines overflowing the max line size (_MAXLINE in http.client)
|
||||
|
||||
def test_overflowing_status_line(self):
|
||||
body = "HTTP/1.1 200 Ok" + "k" * 65536 + "\r\n"
|
||||
resp = client.HTTPResponse(FakeSocket(body))
|
||||
self.assertRaises((client.LineTooLong, client.BadStatusLine), resp.begin)
|
||||
|
||||
def test_overflowing_header_line(self):
|
||||
body = (
|
||||
'HTTP/1.1 200 OK\r\n'
|
||||
'X-Foo: bar' + 'r' * 65536 + '\r\n\r\n'
|
||||
)
|
||||
resp = client.HTTPResponse(FakeSocket(body))
|
||||
self.assertRaises(client.LineTooLong, resp.begin)
|
||||
|
||||
def test_overflowing_chunked_line(self):
|
||||
body = (
|
||||
'HTTP/1.1 200 OK\r\n'
|
||||
'Transfer-Encoding: chunked\r\n\r\n'
|
||||
+ '0' * 65536 + 'a\r\n'
|
||||
'hello world\r\n'
|
||||
'0\r\n'
|
||||
)
|
||||
resp = client.HTTPResponse(FakeSocket(body))
|
||||
resp.begin()
|
||||
self.assertRaises(client.LineTooLong, resp.read)
|
||||
|
||||
class OfflineTest(TestCase):
|
||||
def test_responses(self):
|
||||
self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue