summaryrefslogtreecommitdiff
path: root/cli/dts/lib.deno.ns.d.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-08-02 14:40:46 +0200
committerGitHub <noreply@github.com>2021-08-02 14:40:46 +0200
commit3a2e94492b0d4df1ae5c3bb5a6a6a899538de10b (patch)
tree3e9b89130f95df5b285a50ef273bbbc32c249605 /cli/dts/lib.deno.ns.d.ts
parentf87aa44d94240327fb4ab1dc756d70f71247edb4 (diff)
feat: stabilize Deno.serveHttp() (#11544)
This commit moves "Deno.serveHttp()" and related types to stable namespace.
Diffstat (limited to 'cli/dts/lib.deno.ns.d.ts')
-rw-r--r--cli/dts/lib.deno.ns.d.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index 469b8a329..37cc58ad6 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -2414,4 +2414,33 @@ declare namespace Deno {
* ```
*/
export function fstat(rid: number): Promise<FileInfo>;
+
+ export interface RequestEvent {
+ readonly request: Request;
+ respondWith(r: Response | Promise<Response>): Promise<void>;
+ }
+
+ export interface HttpConn extends AsyncIterable<RequestEvent> {
+ readonly rid: number;
+
+ nextRequest(): Promise<RequestEvent | null>;
+ close(): void;
+ }
+
+ /**
+ * Services HTTP requests given a TCP or TLS socket.
+ *
+ * ```ts
+ * const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
+ * const httpConn = Deno.serveHttp(conn);
+ * const e = await httpConn.nextRequest();
+ * if (e) {
+ * e.respondWith(new Response("Hello World"));
+ * }
+ * ```
+ *
+ * If `httpConn.nextRequest()` encounters an error or returns `null`
+ * then the underlying HttpConn resource is closed automatically.
+ */
+ export function serveHttp(conn: Conn): HttpConn;
}