FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-105626: Change the default return value of `HTTPConnection.get_proxy_response_headers` by sobolevn · Pull Request #105628 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/library/http.client.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions Lib/http/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_httplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Change the default return value of
:meth:`http.client.HTTPConnection.get_proxy_response_headers` to be ``None``
and not ``{}``.

Back | FazBrowse Home | New Git URL