summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/http
diff options
context:
space:
mode:
authorshadchin <[email protected]>2023-12-13 02:43:57 +0300
committershadchin <[email protected]>2023-12-13 03:08:48 +0300
commit5b48aabc614c6d407f885f3b228dc484ad4c5ba9 (patch)
tree602eb5cc5d85bf730c1de1fa50a13c2ee552830d /contrib/tools/python3/src/Lib/http
parent35d7049b38602e8cbfcd3f96257329a1abce947e (diff)
Update Python 3 to 3.11.7
Diffstat (limited to 'contrib/tools/python3/src/Lib/http')
-rw-r--r--contrib/tools/python3/src/Lib/http/client.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/contrib/tools/python3/src/Lib/http/client.py b/contrib/tools/python3/src/Lib/http/client.py
index 1c7f4639db5..87bca4d76ab 100644
--- a/contrib/tools/python3/src/Lib/http/client.py
+++ b/contrib/tools/python3/src/Lib/http/client.py
@@ -172,6 +172,13 @@ def _encode(data, name='data'):
"if you want to send it encoded in UTF-8." %
(name.title(), data[err.start:err.end], name)) from None
+def _strip_ipv6_iface(enc_name: bytes) -> bytes:
+ """Remove interface scope from IPv6 address."""
+ enc_name, percent, _ = enc_name.partition(b"%")
+ if percent:
+ assert enc_name.startswith(b'['), enc_name
+ enc_name += b']'
+ return enc_name
class HTTPMessage(email.message.Message):
# XXX The only usage of this method is in
@@ -1161,7 +1168,7 @@ class HTTPConnection:
netloc_enc = netloc.encode("ascii")
except UnicodeEncodeError:
netloc_enc = netloc.encode("idna")
- self.putheader('Host', netloc_enc)
+ self.putheader('Host', _strip_ipv6_iface(netloc_enc))
else:
if self._tunnel_host:
host = self._tunnel_host
@@ -1178,8 +1185,9 @@ class HTTPConnection:
# As per RFC 273, IPv6 address should be wrapped with []
# when used as Host header
- if host.find(':') >= 0:
+ if ":" in host:
host_enc = b'[' + host_enc + b']'
+ host_enc = _strip_ipv6_iface(host_enc)
if port == self.default_port:
self.putheader('Host', host_enc)