]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105626: Change the default return value of `HTTPConnection.get_proxy_response_head...
authorNikita Sobolev <mail@sobolevn.me>
Fri, 14 Jul 2023 06:55:49 +0000 (09:55 +0300)
committerGitHub <noreply@github.com>
Fri, 14 Jul 2023 06:55:49 +0000 (23:55 -0700)
Doc/library/http.client.rst
Lib/http/client.py
Lib/test/test_httplib.py
Misc/NEWS.d/next/Library/2023-06-10-12-20-17.gh-issue-105626.XyZein.rst [new file with mode: 0644]

index 45291933d635b9c43f003762e24919cc8e9d2437..b9ceab699cef63252fdb68a66b509cbd6b0fdfac 100644 (file)
@@ -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
 
index 3d98e4eb54bb45390115d2c5828d73540728cbd3..b35b1d6368aae7d352677a5289ba1e5fd54024fd 100644 (file)
@@ -970,13 +970,12 @@ class HTTPConnection:
         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):
index 8955d45fa93dd4dec15bc3075c646464a01d3bfb..fe8105ee2bb3faf81c0da3d3965fe12bc25af718 100644 (file)
@@ -2404,6 +2404,19 @@ class TunnelTests(TestCase):
         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 (file)
index 0000000..2a48361
--- /dev/null
@@ -0,0 +1,3 @@
+Change the default return value of
+:meth:`http.client.HTTPConnection.get_proxy_response_headers` to be ``None``
+and not ``{}``.