Skip to content

Commit f97406b

Browse files
authored
bpo-40968: Send http/1.1 ALPN extension (#20959)
Signed-off-by: Christian Heimes <[email protected]>
1 parent 09490a1 commit f97406b

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

Doc/library/http.client.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ The module provides the following classes:
9999
:attr:`ssl.SSLContext.post_handshake_auth` for the default *context* or
100100
when *cert_file* is passed with a custom *context*.
101101

102+
.. versionchanged:: 3.10
103+
This class now sends an ALPN extension with protocol indicator
104+
``http/1.1`` when no *context* is given. Custom *context* should set
105+
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`.
106+
102107
.. deprecated:: 3.6
103108

104109
*key_file* and *cert_file* are deprecated in favor of *context*.

Doc/library/urllib.request.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ The :mod:`urllib.request` module defines the following functions:
109109
.. versionchanged:: 3.4.3
110110
*context* was added.
111111

112+
.. versionchanged:: 3.10
113+
HTTPS connection now send an ALPN extension with protocol indicator
114+
``http/1.1`` when no *context* is given. Custom *context* should set
115+
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`.
116+
112117
.. deprecated:: 3.6
113118

114119
*cafile*, *capath* and *cadefault* are deprecated in favor of *context*.

Lib/http/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,9 @@ def __init__(self, host, port=None, key_file=None, cert_file=None,
14071407
self.cert_file = cert_file
14081408
if context is None:
14091409
context = ssl._create_default_https_context()
1410+
# send ALPN extension to indicate HTTP/1.1 protocol
1411+
if self._http_vsn == 11:
1412+
context.set_alpn_protocols(['http/1.1'])
14101413
# enable PHA for TLS 1.3 connections if available
14111414
if context.post_handshake_auth is not None:
14121415
context.post_handshake_auth = True

Lib/urllib/request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
202202
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH,
203203
cafile=cafile,
204204
capath=capath)
205+
# send ALPN extension to indicate HTTP/1.1 protocol
206+
context.set_alpn_protocols(['http/1.1'])
205207
https_handler = HTTPSHandler(context=context)
206208
opener = build_opener(https_handler)
207209
elif context:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`urllib.request` and :mod:`http.client` now send ``http/1.1`` ALPN
2+
extension during TLS handshake when no custom context is supplied.

0 commit comments

Comments
 (0)