From 6a09a16d710b2d7a9d39478e5bcbabb40919d657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 18 Apr 2024 18:21:08 +0100 Subject: feat(ext/net): extract TLS key and certificate from interfaces (#23327) Relands #23325 --- cli/tsc/dts/lib.deno.ns.d.ts | 33 +++++++++++++++++++++++++++------ cli/tsc/dts/lib.deno.unstable.d.ts | 25 +++++++++++++++++++++---- 2 files changed, 48 insertions(+), 10 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 1d6b398f5..c63b4a261 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -6277,11 +6277,23 @@ declare namespace Deno { * @category HTTP Server */ export interface ServeTlsOptions extends ServeOptions { - /** Server private key in PEM format */ - cert: string; + /** + * Server private key in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead. + * + * @deprecated This will be removed in Deno 2.0. See the + * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} + * for migration instructions. + */ + cert?: string; - /** Cert chain in PEM format */ - key: string; + /** + * Cert chain in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead. + * + * @deprecated This will be removed in Deno 2.0. See the + * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} + * for migration instructions. + */ + key?: string; } /** @@ -6490,7 +6502,10 @@ declare namespace Deno { * @category HTTP Server */ export function serve( - options: ServeOptions | ServeTlsOptions, + options: + | ServeOptions + | ServeTlsOptions + | (ServeTlsOptions & TlsCertifiedKeyOptions), handler: ServeHandler, ): HttpServer; /** Serves HTTP requests with the given option bag. @@ -6546,6 +6561,12 @@ declare namespace Deno { * @category HTTP Server */ export function serve( - options: ServeInit & (ServeOptions | ServeTlsOptions), + options: + & ServeInit + & ( + | ServeOptions + | ServeTlsOptions + | (ServeTlsOptions & TlsCertifiedKeyOptions) + ), ): HttpServer; } diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 056d8e609..ae3f60d28 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -882,10 +882,6 @@ declare namespace Deno { caCerts?: string[]; /** A HTTP proxy to use for new connections. */ proxy?: Proxy; - /** Cert chain in PEM format. */ - cert?: string; - /** Server private key in PEM format. */ - key?: string; /** Sets the maximum numer of idle connections per host allowed in the pool. */ poolMaxIdlePerHost?: number; /** Set an optional timeout for idle sockets being kept-alive. @@ -962,6 +958,27 @@ declare namespace Deno { options: CreateHttpClientOptions, ): HttpClient; + /** **UNSTABLE**: New API, yet to be vetted. + * + * Create a custom HttpClient to use with {@linkcode fetch}. This is an + * extension of the web platform Fetch API which allows Deno to use custom + * TLS certificates and connect via a proxy while using `fetch()`. + * + * @example ```ts + * const caCert = await Deno.readTextFile("./ca.pem"); + * // Load a client key and certificate that we'll use to connect + * const key = await Deno.readTextFile("./key.key"); + * const cert = await Deno.readTextFile("./cert.crt"); + * const client = Deno.createHttpClient({ caCerts: [ caCert ], key, cert }); + * const response = await fetch("https://myserver.com", { client }); + * ``` + * + * @category Fetch API + */ + export function createHttpClient( + options: CreateHttpClientOptions & TlsCertifiedKeyOptions, + ): HttpClient; + /** **UNSTABLE**: New API, yet to be vetted. * * Represents membership of a IPv4 multicast group. -- cgit v1.2.3