Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-69152: add method get_proxy_response_headers to HTTPConnection class#104248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
20 commits Select commitHold shift + click to select a range
d0d9349
add method get_proxy_response_headers
nametkinf39feb9
add method get_proxy_response_headers
nametkin0be0d47
📜🤖 Added by blurb_it.
blurb-it[bot]cdff360
Delete trailing whitespaces
nametkin7288cf6
update docs and news
nametkinf49b56c
merge commit
nametkinb46e44f
Merge branch 'python:main' into new
nametkin2dfc326
delete Misc/NEWS.d/next/Library/2023-05-08-11-52-56.gh-issue-69152.tl…
nametkin70ad871
Merge branch 'new' of https://github.com/OneMoreZanuda/cpython into new
nametkin03a5887
Merge branch 'main' into new
nametkina7af79d
Merge branch 'main' into new
nametkinf1410b5
Merge branch 'main' into new
nametkinb49ec81
Merge branch 'main' into new
nametkinc0f50b9
Merge branch 'main' into new
nametkinfb77b60
Merge branch 'main' into new
nametkin9023028
Merge branch 'main' into new
nametkin63da7f3
Merge branch 'main' into new
nametkin6101344
Merge branch 'main' into new
nametkin5625bfa
Merge branch 'main' into new
nametkina21af19
reworded news and add ReST formatting.
gpsheadFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletionsDoc/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
37 changes: 29 additions & 8 deletionsLib/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 |
---|---|---|
@@ -221,8 +221,9 @@ def _read_headers(fp): | ||
break | ||
return headers | ||
def _parse_header_lines(header_lines, _class=HTTPMessage): | ||
""" | ||
Parses only RFC2822 headers from header lines. | ||
email Parser wants to see strings rather than bytes. | ||
But a TextIOWrapper around self.rfile would buffer too many bytes | ||
@@ -231,10 +232,15 @@ def parse_headers(fp, _class=HTTPMessage): | ||
to parse. | ||
""" | ||
hstring = b''.join(header_lines).decode('iso-8859-1') | ||
return email.parser.Parser(_class=_class).parsestr(hstring) | ||
def parse_headers(fp, _class=HTTPMessage): | ||
"""Parses only RFC2822 headers from a file pointer.""" | ||
headers = _read_headers(fp) | ||
return _parse_header_lines(headers, _class) | ||
class HTTPResponse(io.BufferedIOBase): | ||
@@ -858,7 +864,7 @@ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | ||
self._tunnel_host = None | ||
self._tunnel_port = None | ||
self._tunnel_headers = {} | ||
self._raw_proxy_headers = None | ||
(self.host, self.port) = self._get_hostport(host, port) | ||
@@ -945,11 +951,11 @@ def _tunnel(self): | ||
try: | ||
(version, code, message) = response._read_status() | ||
self._raw_proxy_headers =_read_headers(response.fp) | ||
if self.debuglevel > 0: | ||
forheaderin self._raw_proxy_headers: | ||
print('header:', header.decode()) | ||
if code != http.HTTPStatus.OK: | ||
self.close() | ||
@@ -958,6 +964,21 @@ def _tunnel(self): | ||
finally: | ||
response.close() | ||
def get_proxy_response_headers(self): | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
""" | ||
Returns a dictionary with the headers of the response | ||
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. | ||
""" | ||
return ( | ||
_parse_header_lines(self._raw_proxy_headers) | ||
if self._raw_proxy_headers is not None | ||
else {} | ||
) | ||
def connect(self): | ||
"""Connect to the host and port specified in __init__.""" | ||
sys.audit("http.client.connect", self, self.host, self.port) | ||
2 changes: 1 addition & 1 deletionLib/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
6 changes: 3 additions & 3 deletionsMisc/NEWS.d/next/Library/2021-05-16-14-28-30.bpo-24964.Oa5Ie_.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Added:meth:`http.client.HTTPConnection.get_proxy_response_headers` that | ||
provides access totheHTTPheaderson a proxy server response to the | ||
``CONNECT``request. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.