mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-105626: Change the default return value of HTTPConnection.get_proxy_response_headers
(GH-105628) (#106738)
gh-105626: Change the default return value of `HTTPConnection.get_proxy_response_headers` (GH-105628)
(cherry picked from commit 490295d651
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
6a1a660158
commit
e68b280671
4 changed files with 19 additions and 4 deletions
|
@ -390,7 +390,7 @@ HTTPConnection Objects
|
||||||
Returns a dictionary with the headers of the response received from
|
Returns a dictionary with the headers of the response received from
|
||||||
the proxy server to the CONNECT request.
|
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
|
.. versionadded:: 3.12
|
||||||
|
|
||||||
|
|
|
@ -970,13 +970,12 @@ class HTTPConnection:
|
||||||
received from the proxy server to the CONNECT request
|
received from the proxy server to the CONNECT request
|
||||||
sent to set the tunnel.
|
sent to set the tunnel.
|
||||||
|
|
||||||
If the CONNECT request was not sent, the method returns
|
If the CONNECT request was not sent, the method returns None.
|
||||||
an empty dictionary.
|
|
||||||
"""
|
"""
|
||||||
return (
|
return (
|
||||||
_parse_header_lines(self._raw_proxy_headers)
|
_parse_header_lines(self._raw_proxy_headers)
|
||||||
if self._raw_proxy_headers is not None
|
if self._raw_proxy_headers is not None
|
||||||
else {}
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
|
@ -2404,6 +2404,19 @@ class TunnelTests(TestCase):
|
||||||
headers = self.conn.get_proxy_response_headers()
|
headers = self.conn.get_proxy_response_headers()
|
||||||
self.assertIn(expected_header, headers.items())
|
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):
|
def test_tunnel_leak(self):
|
||||||
sock = None
|
sock = None
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Change the default return value of
|
||||||
|
:meth:`http.client.HTTPConnection.get_proxy_response_headers` to be ``None``
|
||||||
|
and not ``{}``.
|
Loading…
Add table
Add a link
Reference in a new issue