diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 9dbe6817f172c0..d38a0bc4dbce94 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1001,6 +1001,16 @@ declare namespace Deno { options?: StartTlsOptions, ): Promise; + export interface ListenTlsOptions { + /** **UNSTABLE**: new API, yet to be vetted. + * + * Application-Layer Protocol Negotiation (ALPN) protocols to announce to + * the client. If not specified, no ALPN extension will be included in the + * TLS handshake. + */ + alpnProtocols?: string[]; + } + /** **UNSTABLE**: The `signo` argument may change to require the Deno.Signal * enum. * diff --git a/runtime/js/40_tls.js b/runtime/js/40_tls.js index da43afaac283f3..e11754b0d19581 100644 --- a/runtime/js/40_tls.js +++ b/runtime/js/40_tls.js @@ -51,6 +51,7 @@ keyFile, hostname = "0.0.0.0", transport = "tcp", + alpnProtocols, }) { const res = opListenTls({ port, @@ -58,6 +59,7 @@ keyFile, hostname, transport, + alpnProtocols, }); return new TLSListener(res.rid, res.localAddr); } diff --git a/runtime/ops/tls.rs b/runtime/ops/tls.rs index d9c5f1854ab191..83dbbfcd1d688c 100644 --- a/runtime/ops/tls.rs +++ b/runtime/ops/tls.rs @@ -300,6 +300,7 @@ pub struct ListenTlsArgs { port: u16, cert_file: String, key_file: String, + alpn_protocols: Option>, } fn op_listen_tls( @@ -318,6 +319,11 @@ fn op_listen_tls( permissions.read.check(Path::new(&key_file))?; } let mut config = ServerConfig::new(NoClientAuth::new()); + if let Some(alpn_protocols) = args.alpn_protocols { + super::check_unstable(state, "Deno.listenTls#alpn_protocols"); + config.alpn_protocols = + alpn_protocols.into_iter().map(|s| s.into_bytes()).collect(); + } config .set_single_cert(load_certs(&cert_file)?, load_keys(&key_file)?.remove(0)) .expect("invalid key or certificate");