MCPcopy Index your code
hub / github.com/python/cpython / test_max_connection_headers

Method test_max_connection_headers

Lib/test/test_httplib.py:407–434  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

405 resp.begin(_max_headers=max_headers)
406
407 def test_max_connection_headers(self):
408 max_headers = client._MAXHEADERS + 20
409 headers = (
410 f"Name{i}: Value{i}".encode() for i in range(max_headers - 1)
411 )
412 body = (
413 b"HTTP/1.1 200 OK\r\n"
414 + b"\r\n".join(headers)
415 + b"\r\nContent-Length: 12\r\n\r\nDummy body\r\n"
416 )
417
418 with self.subTest(max_headers=None):
419 conn = client.HTTPConnection("example.com")
420 conn.sock = FakeSocket(body)
421 conn.request("GET", "/")
422 with self.assertRaisesRegex(
423 client.HTTPException, f"got more than {client._MAXHEADERS} headers"
424 ):
425 response = conn.getresponse()
426
427 with self.subTest(max_headers=None):
428 conn = client.HTTPConnection(
429 "example.com", max_response_headers=max_headers
430 )
431 conn.sock = FakeSocket(body)
432 conn.request("GET", "/")
433 response = conn.getresponse()
434 response.read()
435
436class HttpMethodTests(TestCase):
437 def test_invalid_method_names(self):

Callers

nothing calls this directly

Calls 8

requestMethod · 0.95
getresponseMethod · 0.95
assertRaisesRegexMethod · 0.80
FakeSocketClass · 0.70
encodeMethod · 0.45
joinMethod · 0.45
subTestMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected