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

Commit ffbe3a3

Browse files
committed
Add stdlib-like ALPN interface for PyOpenSSL
1 parent a679cb9 commit ffbe3a3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

hyper/ssl_compat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ def selected_npn_protocol(self):
149149

150150
return proto if proto else None
151151

152+
def selected_alpn_protocol(self):
153+
proto = self._conn.get_alpn_proto_negotiated()
154+
if isinstance(proto, bytes):
155+
proto = proto.decode('ascii')
156+
157+
return proto if proto else None
158+
152159
def getpeercert(self):
153160
def resolve_alias(alias):
154161
return dict(
@@ -246,6 +253,10 @@ def cb(conn, protos):
246253

247254
self._ctx.set_npn_select_callback(cb)
248255

256+
def set_alpn_protocols(self, protocols):
257+
protocols = list(map(lambda x: x.encode('ascii'), protocols))
258+
self._ctx.set_alpn_protos(protocols)
259+
249260
def wrap_socket(self, sock, server_side=False, do_handshake_on_connect=True,
250261
suppress_ragged_eofs=True, server_hostname=None):
251262
conn = ossl.Connection(self._ctx, sock)

0 commit comments

Comments
 (0)