Skip to content

gh-131724: Add a new max_response_headers param to HTTP/HTTPSConnection #136814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply review comments
  • Loading branch information
aeurielesn committed Jul 19, 2025
commit 34813cae8cb24a34927645b18a5a2600fed2ef54
17 changes: 9 additions & 8 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _get_content_length(body, method):
return None

def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, blocksize=8192, max_headers=None):
source_address=None, blocksize=8192, max_response_headers=None):
self.timeout = timeout
self.source_address = source_address
self.blocksize = blocksize
Expand All @@ -881,9 +881,7 @@ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
self._tunnel_port = None
self._tunnel_headers = {}
self._raw_proxy_headers = None
if max_headers is None:
max_headers = _MAXHEADERS
self.max_headers = max_headers
self.max_response_headers = max_response_headers

(self.host, self.port) = self._get_hostport(host, port)

Expand Down Expand Up @@ -976,7 +974,7 @@ def _tunnel(self):
try:
(version, code, message) = response._read_status()

self._raw_proxy_headers = _read_headers(response.fp, max_headers=self.max_headers)
self._raw_proxy_headers = _read_headers(response.fp, self.max_response_headers)

if self.debuglevel > 0:
for header in self._raw_proxy_headers:
Expand Down Expand Up @@ -1433,7 +1431,10 @@ def getresponse(self):

try:
try:
response.begin(_max_headers=self.max_headers)
if self.max_response_headers is None:
response.begin()
else:
response.begin(self.max_response_headers)
except ConnectionError:
self.close()
raise
Expand Down Expand Up @@ -1465,11 +1466,11 @@ class HTTPSConnection(HTTPConnection):
def __init__(self, host, port=None,
*, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, context=None, blocksize=8192,
max_headers=None):
max_response_headers=None):
super(HTTPSConnection, self).__init__(host, port, timeout,
source_address,
blocksize=blocksize,
max_headers=max_headers)
max_response_headers=max_response_headers)
if context is None:
context = _create_https_context(self._http_vsn)
self._context = context
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ def test_max_connection_headers(self):
response = conn.getresponse()

with self.subTest(max_headers=None):
conn = client.HTTPConnection("example.com", max_headers=max_headers)
conn = client.HTTPConnection(
"example.com", max_response_headers=max_headers
)
conn.sock = FakeSocket(body)
conn.request("GET", "/")
response = conn.getresponse()
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy