2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-06-28 19:43:03 -04:00
|
|
|
|
|
|
|
/// <reference no-default-lib="true" />
|
|
|
|
/// <reference lib="esnext" />
|
2023-11-01 15:26:12 -04:00
|
|
|
/// <reference lib="esnext.disposable" />
|
2021-06-28 19:43:03 -04:00
|
|
|
|
|
|
|
declare namespace Deno {
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export interface NetAddr {
|
|
|
|
transport: "tcp" | "udp";
|
|
|
|
hostname: string;
|
|
|
|
port: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export interface UnixAddr {
|
|
|
|
transport: "unix" | "unixpacket";
|
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export type Addr = NetAddr | UnixAddr;
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** A generic network listener for stream-oriented protocols.
|
|
|
|
*
|
|
|
|
* @category Network
|
|
|
|
*/
|
2024-04-05 19:01:03 -04:00
|
|
|
export interface Listener<T extends Conn = Conn, A extends Addr = Addr>
|
2023-11-01 15:26:12 -04:00
|
|
|
extends AsyncIterable<T>, Disposable {
|
2021-06-28 19:43:03 -04:00
|
|
|
/** Waits for and resolves to the next connection to the `Listener`. */
|
2023-08-27 16:55:04 -04:00
|
|
|
accept(): Promise<T>;
|
2021-06-28 19:43:03 -04:00
|
|
|
/** Close closes the listener. Any pending accept promises will be rejected
|
2021-09-02 18:28:12 -04:00
|
|
|
* with errors. */
|
2021-06-28 19:43:03 -04:00
|
|
|
close(): void;
|
|
|
|
/** Return the address of the `Listener`. */
|
2024-04-05 19:01:03 -04:00
|
|
|
readonly addr: A;
|
2021-06-28 19:43:03 -04:00
|
|
|
|
2024-01-24 12:52:55 -05:00
|
|
|
/**
|
|
|
|
* Return the rid of the `Listener`.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-24 12:52:55 -05:00
|
|
|
*/
|
2021-06-28 19:43:03 -04:00
|
|
|
readonly rid: number;
|
|
|
|
|
2023-08-27 16:55:04 -04:00
|
|
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
2023-01-20 10:32:55 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the listener block the event loop from finishing.
|
|
|
|
*
|
|
|
|
* Note: the listener blocks the event loop from finishing by default.
|
|
|
|
* This method is only meaningful after `.unref()` is called.
|
|
|
|
*/
|
|
|
|
ref(): void;
|
|
|
|
|
|
|
|
/** Make the listener not block the event loop from finishing. */
|
|
|
|
unref(): void;
|
2021-06-28 19:43:03 -04:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** Specialized listener that accepts TLS connections.
|
|
|
|
*
|
|
|
|
* @category Network
|
|
|
|
*/
|
2024-04-05 19:01:03 -04:00
|
|
|
export type TlsListener = Listener<TlsConn, NetAddr>;
|
|
|
|
|
|
|
|
/** Specialized listener that accepts TCP connections.
|
|
|
|
*
|
|
|
|
* @category Network
|
|
|
|
*/
|
|
|
|
export type TcpListener = Listener<TcpConn, NetAddr>;
|
|
|
|
|
|
|
|
/** Specialized listener that accepts Unix connections.
|
|
|
|
*
|
|
|
|
* @category Network
|
|
|
|
*/
|
|
|
|
export type UnixListener = Listener<UnixConn, UnixAddr>;
|
2021-10-26 16:27:47 -04:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2024-04-05 19:01:03 -04:00
|
|
|
export interface Conn<A extends Addr = Addr>
|
|
|
|
extends Reader, Writer, Closer, Disposable {
|
2021-06-28 19:43:03 -04:00
|
|
|
/** The local address of the connection. */
|
2024-04-05 19:01:03 -04:00
|
|
|
readonly localAddr: A;
|
2021-06-28 19:43:03 -04:00
|
|
|
/** The remote address of the connection. */
|
2024-04-05 19:01:03 -04:00
|
|
|
readonly remoteAddr: A;
|
2024-01-24 16:12:10 -05:00
|
|
|
/**
|
|
|
|
* The resource ID of the connection.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-24 16:12:10 -05:00
|
|
|
*/
|
2021-06-28 19:43:03 -04:00
|
|
|
readonly rid: number;
|
|
|
|
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
2021-09-02 18:28:12 -04:00
|
|
|
* callers should just use `close()`. */
|
2021-06-28 19:43:03 -04:00
|
|
|
closeWrite(): Promise<void>;
|
2022-02-15 07:35:22 -05:00
|
|
|
|
2024-01-14 12:04:33 -05:00
|
|
|
/** Make the connection block the event loop from finishing.
|
2022-12-28 04:29:48 -05:00
|
|
|
*
|
|
|
|
* Note: the connection blocks the event loop from finishing by default.
|
|
|
|
* This method is only meaningful after `.unref()` is called.
|
|
|
|
*/
|
|
|
|
ref(): void;
|
2024-01-14 12:04:33 -05:00
|
|
|
/** Make the connection not block the event loop from finishing. */
|
2022-12-28 04:29:48 -05:00
|
|
|
unref(): void;
|
|
|
|
|
2022-02-15 07:35:22 -05:00
|
|
|
readonly readable: ReadableStream<Uint8Array>;
|
|
|
|
readonly writable: WritableStream<Uint8Array>;
|
2021-06-28 19:43:03 -04:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2024-01-14 12:06:26 -05:00
|
|
|
export interface TlsHandshakeInfo {
|
|
|
|
/**
|
|
|
|
* Contains the ALPN protocol selected during negotiation with the server.
|
|
|
|
* If no ALPN protocol selected, returns `null`.
|
|
|
|
*/
|
|
|
|
alpnProtocol: string | null;
|
|
|
|
}
|
2021-11-26 13:59:53 -05:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2024-04-05 19:01:03 -04:00
|
|
|
export interface TlsConn extends Conn<NetAddr> {
|
2021-10-26 16:27:47 -04:00
|
|
|
/** Runs the client or server handshake protocol to completion if that has
|
|
|
|
* not happened yet. Calling this method is optional; the TLS handshake
|
|
|
|
* will be completed automatically as soon as data is sent or received. */
|
2021-11-26 13:59:53 -05:00
|
|
|
handshake(): Promise<TlsHandshakeInfo>;
|
2024-01-24 16:12:10 -05:00
|
|
|
/**
|
|
|
|
* The resource ID of the connection.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-24 16:12:10 -05:00
|
|
|
*/
|
|
|
|
readonly rid: number;
|
2021-10-26 16:27:47 -04:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export interface ListenOptions {
|
|
|
|
/** The port to listen on. */
|
|
|
|
port: number;
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2021-09-07 03:26:21 -04:00
|
|
|
*
|
|
|
|
* __Note about `0.0.0.0`__ While listening `0.0.0.0` works on all platforms,
|
|
|
|
* the browsers on Windows don't work with the address `0.0.0.0`.
|
|
|
|
* You should show the message like `server running on localhost:8080` instead of
|
2022-12-13 08:14:41 -05:00
|
|
|
* `server running on 0.0.0.0:8080` if your program supports Windows.
|
|
|
|
*
|
|
|
|
* @default {"0.0.0.0"} */
|
2021-06-28 19:43:03 -04:00
|
|
|
hostname?: string;
|
|
|
|
}
|
|
|
|
|
2022-10-26 15:04:27 -04:00
|
|
|
/** @category Network */
|
|
|
|
// deno-lint-ignore no-empty-interface
|
|
|
|
export interface TcpListenOptions extends ListenOptions {
|
|
|
|
}
|
|
|
|
|
2021-06-28 19:43:03 -04:00
|
|
|
/** Listen announces on the local transport address.
|
2021-09-02 18:28:12 -04:00
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const listener1 = Deno.listen({ port: 80 })
|
|
|
|
* const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 })
|
|
|
|
* const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
* const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
* ```
|
|
|
|
*
|
2022-08-16 23:12:24 -04:00
|
|
|
* Requires `allow-net` permission.
|
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-net
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
|
|
|
*/
|
2021-06-28 19:43:03 -04:00
|
|
|
export function listen(
|
2022-10-26 15:04:27 -04:00
|
|
|
options: TcpListenOptions & { transport?: "tcp" },
|
2024-04-05 19:01:03 -04:00
|
|
|
): TcpListener;
|
2021-06-28 19:43:03 -04:00
|
|
|
|
2024-01-23 07:02:25 -05:00
|
|
|
/** Options which can be set when opening a Unix listener via
|
|
|
|
* {@linkcode Deno.listen} or {@linkcode Deno.listenDatagram}.
|
|
|
|
*
|
|
|
|
* @category Network
|
|
|
|
*/
|
|
|
|
export interface UnixListenOptions {
|
|
|
|
/** A path to the Unix Socket. */
|
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Listen announces on the local transport address.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" })
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Requires `allow-read` and `allow-write` permission.
|
|
|
|
*
|
|
|
|
* @tags allow-read, allow-write
|
|
|
|
* @category Network
|
|
|
|
*/
|
|
|
|
// deno-lint-ignore adjacent-overload-signatures
|
|
|
|
export function listen(
|
|
|
|
options: UnixListenOptions & { transport: "unix" },
|
2024-04-05 19:01:03 -04:00
|
|
|
): UnixListener;
|
2024-01-23 07:02:25 -05:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2022-10-26 15:04:27 -04:00
|
|
|
export interface ListenTlsOptions extends TcpListenOptions {
|
2022-02-23 23:16:56 -05:00
|
|
|
/** Server private key in PEM format */
|
|
|
|
key?: string;
|
|
|
|
/** Cert chain in PEM format */
|
|
|
|
cert?: string;
|
2021-08-09 09:55:00 -04:00
|
|
|
/** Path to a file containing a PEM formatted CA certificate. Requires
|
2022-02-23 23:16:56 -05:00
|
|
|
* `--allow-read`.
|
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-read
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2022-02-23 23:16:56 -05:00
|
|
|
*/
|
|
|
|
certFile?: string;
|
|
|
|
/** Server private key file. Requires `--allow-read`.
|
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-read
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2022-02-23 23:16:56 -05:00
|
|
|
*/
|
|
|
|
keyFile?: string;
|
2021-06-28 19:43:03 -04:00
|
|
|
|
|
|
|
transport?: "tcp";
|
2023-07-04 09:28:50 -04:00
|
|
|
|
|
|
|
/** 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[];
|
2021-06-28 19:43:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Listen announces on the local transport address over TLS (transport layer
|
2021-09-02 18:28:12 -04:00
|
|
|
* security).
|
|
|
|
*
|
|
|
|
* ```ts
|
2024-01-23 11:35:23 -05:00
|
|
|
* using listener = Deno.listenTls({
|
|
|
|
* port: 443,
|
|
|
|
* cert: Deno.readTextFileSync("./server.crt"),
|
|
|
|
* key: Deno.readTextFileSync("./server.key"),
|
|
|
|
* });
|
2021-09-02 18:28:12 -04:00
|
|
|
* ```
|
|
|
|
*
|
2022-08-16 23:12:24 -04:00
|
|
|
* Requires `allow-net` permission.
|
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-net
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
|
|
|
*/
|
2021-10-26 16:27:47 -04:00
|
|
|
export function listenTls(options: ListenTlsOptions): TlsListener;
|
2021-06-28 19:43:03 -04:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export interface ConnectOptions {
|
|
|
|
/** The port to connect to. */
|
|
|
|
port: number;
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 08:14:41 -05:00
|
|
|
* If not specified,
|
|
|
|
*
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-06-28 19:43:03 -04:00
|
|
|
hostname?: string;
|
|
|
|
transport?: "tcp";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-02 18:28:12 -04:00
|
|
|
* Connects to the hostname (default is "127.0.0.1") and port on the named
|
|
|
|
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const conn1 = await Deno.connect({ port: 80 });
|
|
|
|
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
|
|
|
|
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
* ```
|
|
|
|
*
|
2022-08-16 23:12:24 -04:00
|
|
|
* Requires `allow-net` permission for "tcp".
|
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-net
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
|
|
|
*/
|
2022-02-27 09:18:30 -05:00
|
|
|
export function connect(options: ConnectOptions): Promise<TcpConn>;
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2024-04-05 19:01:03 -04:00
|
|
|
export interface TcpConn extends Conn<NetAddr> {
|
2022-02-27 09:18:30 -05:00
|
|
|
/**
|
2022-12-13 08:14:41 -05:00
|
|
|
* Enable/disable the use of Nagle's algorithm.
|
|
|
|
*
|
2022-12-13 18:54:11 -05:00
|
|
|
* @param [noDelay=true]
|
2022-02-27 09:18:30 -05:00
|
|
|
*/
|
2022-12-13 18:54:11 -05:00
|
|
|
setNoDelay(noDelay?: boolean): void;
|
|
|
|
/** Enable/disable keep-alive functionality. */
|
|
|
|
setKeepAlive(keepAlive?: boolean): void;
|
2024-01-24 16:12:10 -05:00
|
|
|
/**
|
|
|
|
* The resource ID of the connection.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-24 16:12:10 -05:00
|
|
|
*/
|
|
|
|
readonly rid: number;
|
2022-02-27 09:18:30 -05:00
|
|
|
}
|
2021-06-28 19:43:03 -04:00
|
|
|
|
2024-01-14 16:50:58 -05:00
|
|
|
/** @category Network */
|
|
|
|
export interface UnixConnectOptions {
|
|
|
|
transport: "unix";
|
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2024-04-05 19:01:03 -04:00
|
|
|
export interface UnixConn extends Conn<UnixAddr> {
|
2024-01-24 16:12:10 -05:00
|
|
|
/**
|
|
|
|
* The resource ID of the connection.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-24 16:12:10 -05:00
|
|
|
*/
|
|
|
|
readonly rid: number;
|
|
|
|
}
|
2022-03-04 14:33:13 -05:00
|
|
|
|
2024-01-14 16:50:58 -05:00
|
|
|
/** Connects to the hostname (default is "127.0.0.1") and port on the named
|
|
|
|
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const conn1 = await Deno.connect({ port: 80 });
|
|
|
|
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
|
|
|
|
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
* const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" });
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Requires `allow-net` permission for "tcp" and `allow-read` for "unix".
|
|
|
|
*
|
|
|
|
* @tags allow-net, allow-read
|
|
|
|
* @category Network
|
|
|
|
*/
|
|
|
|
// deno-lint-ignore adjacent-overload-signatures
|
|
|
|
export function connect(options: UnixConnectOptions): Promise<UnixConn>;
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-06-28 19:43:03 -04:00
|
|
|
export interface ConnectTlsOptions {
|
|
|
|
/** The port to connect to. */
|
|
|
|
port: number;
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 08:14:41 -05:00
|
|
|
*
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-06-28 19:43:03 -04:00
|
|
|
hostname?: string;
|
2021-09-30 03:26:15 -04:00
|
|
|
/**
|
2021-12-09 19:05:50 -05:00
|
|
|
* Server certificate file.
|
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2021-09-30 03:26:15 -04:00
|
|
|
*/
|
2021-06-28 19:43:03 -04:00
|
|
|
certFile?: string;
|
2021-09-30 03:26:15 -04:00
|
|
|
/** A list of root certificates that will be used in addition to the
|
|
|
|
* default root certificates to verify the peer's certificate.
|
|
|
|
*
|
|
|
|
* Must be in PEM format. */
|
|
|
|
caCerts?: string[];
|
2023-07-04 09:28:50 -04:00
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols supported by
|
|
|
|
* the client. If not specified, no ALPN extension will be included in the
|
|
|
|
* TLS handshake.
|
|
|
|
*/
|
|
|
|
alpnProtocols?: string[];
|
2024-02-18 09:30:58 -05:00
|
|
|
/**
|
|
|
|
* PEM formatted client certificate chain.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2024-01-14 12:06:26 -05:00
|
|
|
certChain?: string;
|
2024-02-18 09:30:58 -05:00
|
|
|
/**
|
|
|
|
* PEM formatted (RSA or PKCS8) private key of client certificate.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2024-01-14 12:06:26 -05:00
|
|
|
privateKey?: string;
|
2024-02-18 09:30:58 -05:00
|
|
|
/** Server private key in PEM format. */
|
|
|
|
key?: string;
|
|
|
|
/** Cert chain in PEM format. */
|
|
|
|
cert?: string;
|
2021-06-28 19:43:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Establishes a secure connection over TLS (transport layer security) using
|
2021-09-02 18:28:12 -04:00
|
|
|
* an optional cert file, hostname (default is "127.0.0.1") and port. The
|
|
|
|
* cert file is optional and if not included Mozilla's root certificates will
|
|
|
|
* be used (see also https://github.com/ctz/webpki-roots for specifics)
|
|
|
|
*
|
|
|
|
* ```ts
|
2021-09-30 03:26:15 -04:00
|
|
|
* const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
|
2021-09-02 18:28:12 -04:00
|
|
|
* const conn1 = await Deno.connectTls({ port: 80 });
|
2021-09-30 03:26:15 -04:00
|
|
|
* const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "192.0.2.1", port: 80 });
|
2021-09-02 18:28:12 -04:00
|
|
|
* const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 });
|
2021-09-30 03:26:15 -04:00
|
|
|
* const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "golang.org", port: 80});
|
2021-09-02 18:28:12 -04:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Requires `allow-net` permission.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-net
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
2021-09-02 18:28:12 -04:00
|
|
|
*/
|
2021-10-26 16:27:47 -04:00
|
|
|
export function connectTls(options: ConnectTlsOptions): Promise<TlsConn>;
|
2021-06-28 19:43:03 -04:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Network */
|
2021-10-29 11:13:31 -04:00
|
|
|
export interface StartTlsOptions {
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 08:14:41 -05:00
|
|
|
*
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-10-29 11:13:31 -04:00
|
|
|
hostname?: string;
|
|
|
|
/** A list of root certificates that will be used in addition to the
|
|
|
|
* default root certificates to verify the peer's certificate.
|
|
|
|
*
|
|
|
|
* Must be in PEM format. */
|
|
|
|
caCerts?: string[];
|
2023-07-04 09:28:50 -04:00
|
|
|
/** 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[];
|
2021-10-29 11:13:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Start TLS handshake from an existing connection using an optional list of
|
|
|
|
* CA certificates, and hostname (default is "127.0.0.1"). Specifying CA certs
|
|
|
|
* is optional. By default the configured root certificates are used. Using
|
|
|
|
* this function requires that the other end of the connection is prepared for
|
|
|
|
* a TLS handshake.
|
|
|
|
*
|
2022-10-17 22:28:27 -04:00
|
|
|
* Note that this function *consumes* the TCP connection passed to it, thus the
|
|
|
|
* original TCP connection will be unusable after calling this. Additionally,
|
|
|
|
* you need to ensure that the TCP connection is not being used elsewhere when
|
|
|
|
* calling this function in order for the TCP connection to be consumed properly.
|
|
|
|
* For instance, if there is a `Promise` that is waiting for read operation on
|
|
|
|
* the TCP connection to complete, it is considered that the TCP connection is
|
|
|
|
* being used elsewhere. In such a case, this function will fail.
|
|
|
|
*
|
2021-10-29 11:13:31 -04:00
|
|
|
* ```ts
|
|
|
|
* const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
|
|
|
|
* const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
|
2022-10-17 22:28:27 -04:00
|
|
|
* // `conn` becomes unusable after calling `Deno.startTls`
|
2021-10-29 11:13:31 -04:00
|
|
|
* const tlsConn = await Deno.startTls(conn, { caCerts: [caCert], hostname: "localhost" });
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Requires `allow-net` permission.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2022-08-22 20:57:01 -04:00
|
|
|
* @tags allow-net
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
2021-10-29 11:13:31 -04:00
|
|
|
*/
|
|
|
|
export function startTls(
|
2024-04-05 19:01:03 -04:00
|
|
|
conn: TcpConn,
|
2021-10-29 11:13:31 -04:00
|
|
|
options?: StartTlsOptions,
|
|
|
|
): Promise<TlsConn>;
|
|
|
|
|
2021-06-28 19:43:03 -04:00
|
|
|
/** Shutdown socket send operations.
|
2021-09-02 18:28:12 -04:00
|
|
|
*
|
|
|
|
* Matches behavior of POSIX shutdown(3).
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const listener = Deno.listen({ port: 80 });
|
|
|
|
* const conn = await listener.accept();
|
|
|
|
* Deno.shutdown(conn.rid);
|
|
|
|
* ```
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2024-02-07 17:42:33 -05:00
|
|
|
* @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.
|
2024-01-23 21:47:48 -05:00
|
|
|
*
|
2022-08-16 23:12:24 -04:00
|
|
|
* @category Network
|
2021-09-02 18:28:12 -04:00
|
|
|
*/
|
2021-06-28 19:43:03 -04:00
|
|
|
export function shutdown(rid: number): Promise<void>;
|
|
|
|
}
|