Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 70924f0

Browse files
committed
Make ALPN calls.
1 parent ffbe3a3 commit 70924f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hyper/tls.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ def wrap_socket(sock, server_hostname):
4545
ssl.verify_hostname(ssl_sock, server_hostname) # pyopenssl
4646

4747
proto = None
48+
49+
# ALPN is newer, so we prefer it over NPN. The odds of us getting different
50+
# answers is pretty low, but let's be sure.
51+
with ignore_missing():
52+
proto = ssl_sock.selected_alpn_protocol()
53+
4854
with ignore_missing():
49-
proto = ssl_sock.selected_npn_protocol()
55+
if proto is None:
56+
proto = ssl_sock.selected_npn_protocol()
5057

5158
return (ssl_sock, proto)
5259

@@ -64,6 +71,9 @@ def _init_context():
6471
with ignore_missing():
6572
context.set_npn_protocols(SUPPORTED_NPN_PROTOCOLS)
6673

74+
with ignore_missing():
75+
context.set_alpn_protocols(SUPPORTED_NPN_PROTOCOLS)
76+
6777
# required by the spec
6878
context.options |= ssl.OP_NO_COMPRESSION
6979

0 commit comments

Comments
 (0)