Skip to content

Commit 50ae969

Browse files
committed
pythongh-105626: Change the default return value of HTTPConnection.get_proxy_response_headers
1 parent d636d7d commit 50ae969

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Doc/library/http.client.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ HTTPConnection Objects
390390
Returns a dictionary with the headers of the response received from
391391
the proxy server to the CONNECT request.
392392

393-
If the CONNECT request was not sent, the method returns an empty dictionary.
393+
If the CONNECT request was not sent, the method returns ``None``.
394394

395395
.. versionadded:: 3.12
396396

Lib/http/client.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,12 @@ def get_proxy_response_headers(self):
970970
received from the proxy server to the CONNECT request
971971
sent to set the tunnel.
972972
973-
If the CONNECT request was not sent, the method returns
974-
an empty dictionary.
973+
If the CONNECT request was not sent, the method returns None.
975974
"""
976975
return (
977976
_parse_header_lines(self._raw_proxy_headers)
978977
if self._raw_proxy_headers is not None
979-
else {}
978+
else None
980979
)
981980

982981
def connect(self):

Lib/test/test_httplib.py

+13
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,19 @@ def test_proxy_response_headers(self):
24042404
headers = self.conn.get_proxy_response_headers()
24052405
self.assertIn(expected_header, headers.items())
24062406

2407+
def test_no_proxy_response_headers(self):
2408+
expected_header = ('X-Dummy', '1')
2409+
response_text = (
2410+
'HTTP/1.0 200 OK\r\n'
2411+
'{0}\r\n\r\n'.format(':'.join(expected_header))
2412+
)
2413+
2414+
self.conn._create_connection = self._create_connection(response_text)
2415+
2416+
self.conn.request('PUT', '/', '')
2417+
headers = self.conn.get_proxy_response_headers()
2418+
self.assertIsNone(headers)
2419+
24072420
def test_tunnel_leak(self):
24082421
sock = None
24092422

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Change the default return value of
2+
:meth:`http.client.HTTPConnection.get_proxy_response_headers` to be ``None``
3+
and not ``{}``.

0 commit comments

Comments
 (0)