[Python-checkins] gh-105626: Change the default return value of `HTTPConnection.get_proxy_response_headers` (#105628)

gpshead webhook-mailer at python.org
Fri Jul 14 02:55:52 EDT 2023


https://github.com/python/cpython/commit/490295d651d04ec3b3eff2a2cda7501191bad78a
commit: 490295d651d04ec3b3eff2a2cda7501191bad78a
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: gpshead <greg at krypto.org>
date: 2023-07-13T23:55:49-07:00
summary:

gh-105626: Change the default return value of `HTTPConnection.get_proxy_response_headers` (#105628)

files:
A Misc/NEWS.d/next/Library/2023-06-10-12-20-17.gh-issue-105626.XyZein.rst
M Doc/library/http.client.rst
M Lib/http/client.py
M Lib/test/test_httplib.py

diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst
index 45291933d635b..b9ceab699cef6 100644
--- a/Doc/library/http.client.rst
+++ b/Doc/library/http.client.rst
@@ -390,7 +390,7 @@ HTTPConnection Objects
    Returns a dictionary with the headers of the response received from
    the proxy server to the CONNECT request.
 
-   If the CONNECT request was not sent, the method returns an empty dictionary.
+   If the CONNECT request was not sent, the method returns ``None``.
 
    .. versionadded:: 3.12
 
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 3d98e4eb54bb4..b35b1d6368aae 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -970,13 +970,12 @@ def get_proxy_response_headers(self):
         received from the proxy server to the CONNECT request
         sent to set the tunnel.
 
-        If the CONNECT request was not sent, the method returns
-        an empty dictionary.
+        If the CONNECT request was not sent, the method returns None.
         """
         return (
             _parse_header_lines(self._raw_proxy_headers)
             if self._raw_proxy_headers is not None
-            else {}
+            else None
         )
 
     def connect(self):
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 8955d45fa93dd..fe8105ee2bb3f 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -2404,6 +2404,19 @@ def test_proxy_response_headers(self):
         headers = self.conn.get_proxy_response_headers()
         self.assertIn(expected_header, headers.items())
 
+    def test_no_proxy_response_headers(self):
+        expected_header = ('X-Dummy', '1')
+        response_text = (
+            'HTTP/1.0 200 OK\r\n'
+            '{0}\r\n\r\n'.format(':'.join(expected_header))
+        )
+
+        self.conn._create_connection = self._create_connection(response_text)
+
+        self.conn.request('PUT', '/', '')
+        headers = self.conn.get_proxy_response_headers()
+        self.assertIsNone(headers)
+
     def test_tunnel_leak(self):
         sock = None
 
diff --git a/Misc/NEWS.d/next/Library/2023-06-10-12-20-17.gh-issue-105626.XyZein.rst b/Misc/NEWS.d/next/Library/2023-06-10-12-20-17.gh-issue-105626.XyZein.rst
new file mode 100644
index 0000000000000..2a48361fa596c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-06-10-12-20-17.gh-issue-105626.XyZein.rst
@@ -0,0 +1,3 @@
+Change the default return value of
+:meth:`http.client.HTTPConnection.get_proxy_response_headers` to be ``None``
+and not ``{}``.



More information about the Python-checkins mailing list