Skip to content

Commit a748bfe

Browse files
committed
feat(unstable): ALPN config in listenTls
This commit adds the ability for users to configure ALPN protocols when calling `Deno.listenTls`.
1 parent a87da4b commit a748bfe

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

cli/dts/lib.deno.unstable.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,16 @@ declare namespace Deno {
10011001
options?: StartTlsOptions,
10021002
): Promise<Conn>;
10031003

1004+
export interface ListenTlsOptions {
1005+
/** **UNSTABLE**: new API, yet to be vetted.
1006+
*
1007+
* Application-Layer Protocol Negotiation (ALPN) protocols to announce to
1008+
* the client. If not specified, no ALPN extension will be included in the
1009+
* TLS handshake.
1010+
*/
1011+
alpnProtocols?: string[];
1012+
}
1013+
10041014
/** **UNSTABLE**: The `signo` argument may change to require the Deno.Signal
10051015
* enum.
10061016
*

runtime/js/40_tls.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151
keyFile,
5252
hostname = "0.0.0.0",
5353
transport = "tcp",
54+
alpnProtocols,
5455
}) {
5556
const res = opListenTls({
5657
port,
5758
certFile,
5859
keyFile,
5960
hostname,
6061
transport,
62+
alpnProtocols,
6163
});
6264
return new TLSListener(res.rid, res.localAddr);
6365
}

runtime/ops/tls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ pub struct ListenTlsArgs {
300300
port: u16,
301301
cert_file: String,
302302
key_file: String,
303+
alpn_protocols: Option<Vec<String>>,
303304
}
304305

305306
fn op_listen_tls(
@@ -318,6 +319,11 @@ fn op_listen_tls(
318319
permissions.read.check(Path::new(&key_file))?;
319320
}
320321
let mut config = ServerConfig::new(NoClientAuth::new());
322+
if let Some(alpn_protocols) = args.alpn_protocols {
323+
super::check_unstable(state, "Deno.listenTls#alpn_protocols");
324+
config.alpn_protocols =
325+
alpn_protocols.into_iter().map(|s| s.into_bytes()).collect();
326+
}
321327
config
322328
.set_single_cert(load_certs(&cert_file)?, load_keys(&key_file)?.remove(0))
323329
.expect("invalid key or certificate");

0 commit comments

Comments
 (0)