1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

feat: stabilize Deno.serveHttp() (#11544)

This commit moves "Deno.serveHttp()" and related types
to stable namespace.
This commit is contained in:
Bartek Iwańczuk 2021-08-02 14:40:46 +02:00 committed by GitHub
parent f87aa44d94
commit 3a2e94492b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 35 deletions

View file

@ -203,7 +203,6 @@ fn deno_http_native(deno_exe: &str) -> Result<HttpBenchmarkResult> {
"run",
"--allow-net",
"--reload",
"--unstable",
"cli/bench/deno_http_native.js",
&server_addr(port),
],

View file

@ -25,7 +25,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"EmitOptions",
"EmitResult",
"HttpClient",
"HttpConn",
"LinuxSignal",
"Location",
"MXRecord",
@ -33,7 +32,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"Metrics",
"OpMetrics",
"RecordType",
"RequestEvent",
"ResolveDnsOptions",
"SRVRecord",
"SetRawOptions",
@ -60,7 +58,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"osRelease",
"ppid",
"resolveDns",
"serveHttp",
"setRaw",
"shutdown",
"signal",

View file

@ -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;
}

View file

@ -1076,24 +1076,6 @@ declare namespace Deno {
write?: "inherit" | boolean | Array<string | URL>;
};
}
/** **UNSTABLE**: new API, yet to be vetted.
*
* 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;
}
declare function fetch(

View file

@ -4,18 +4,6 @@
/// <reference lib="esnext" />
declare namespace Deno {
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;
}
export interface WebSocketUpgrade {
response: Response;
socket: WebSocket;

View file

@ -101,6 +101,7 @@
permissions: __bootstrap.permissions.permissions,
Permissions: __bootstrap.permissions.Permissions,
PermissionStatus: __bootstrap.permissions.PermissionStatus,
serveHttp: __bootstrap.http.serveHttp,
};
__bootstrap.denoNsUnstable = {
@ -125,7 +126,6 @@
listen: __bootstrap.netUnstable.listen,
connect: __bootstrap.netUnstable.connect,
listenDatagram: __bootstrap.netUnstable.listenDatagram,
serveHttp: __bootstrap.http.serveHttp,
startTls: __bootstrap.tls.startTls,
umask: __bootstrap.fs.umask,
upgradeWebSocket: __bootstrap.http.upgradeWebSocket,