Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a60f7b

Browse files
committed
add method get_proxy_response_headers
1 parentde7f694 commit2a60f7b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

‎Lib/http/client.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def _read_headers(fp):
221221
break
222222
returnheaders
223223

224-
defparse_headers(fp,_class=HTTPMessage):
225-
"""Parses only RFC2822 headers froma file pointer.
224+
def_parse_header_lines(header_lines,_class=HTTPMessage):
225+
"""Parses only RFC2822 headers fromheader lines.
226226
227227
email Parser wants to see strings rather than bytes.
228228
But a TextIOWrapper around self.rfile would buffer too many bytes
@@ -231,10 +231,13 @@ def parse_headers(fp, _class=HTTPMessage):
231231
to parse.
232232
233233
"""
234-
headers=_read_headers(fp)
235-
hstring=b''.join(headers).decode('iso-8859-1')
234+
hstring=b''.join(header_lines).decode('iso-8859-1')
236235
returnemail.parser.Parser(_class=_class).parsestr(hstring)
237236

237+
defparse_headers(fp,_class=HTTPMessage):
238+
headers=_read_headers(fp)
239+
return_parse_header_lines(headers,_class)
240+
238241

239242
classHTTPResponse(io.BufferedIOBase):
240243

@@ -858,7 +861,7 @@ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
858861
self._tunnel_host=None
859862
self._tunnel_port=None
860863
self._tunnel_headers= {}
861-
self._proxy_response_headers=None
864+
self._raw_proxy_headers=None
862865

863866
(self.host,self.port)=self._get_hostport(host,port)
864867

@@ -945,11 +948,11 @@ def _tunnel(self):
945948
try:
946949
(version,code,message)=response._read_status()
947950

948-
self._proxy_response_headers=parse_headers(response.fp)
951+
self._raw_proxy_headers=_read_headers(response.fp)
949952

950953
ifself.debuglevel>0:
951-
forhdr,valinself._proxy_response_headers.items():
952-
print("header:",hdr+":",val)
954+
forheaderinself._raw_proxy_headers:
955+
print('header:',header.decode())
953956

954957
ifcode!=http.HTTPStatus.OK:
955958
self.close()
@@ -958,6 +961,13 @@ def _tunnel(self):
958961
finally:
959962
response.close()
960963

964+
defget_proxy_response_headers(self):
965+
return (
966+
_parse_header_lines(self._raw_proxy_headers)
967+
ifself._raw_proxy_headersisnotNone
968+
elseNone
969+
)
970+
961971
defconnect(self):
962972
"""Connect to the host and port specified in __init__."""
963973
sys.audit("http.client.connect",self,self.host,self.port)

‎Lib/test/test_httplib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ def test_proxy_response_headers(self):
24012401
self.conn.set_tunnel('destination.com')
24022402

24032403
self.conn.request('PUT','/','')
2404-
headers=self.conn._proxy_response_headers
2404+
headers=self.conn.get_proxy_response_headers()
24052405
self.assertIn(expected_header,headers.items())
24062406

24072407
deftest_tunnel_leak(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp