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", "run",
"--allow-net", "--allow-net",
"--reload", "--reload",
"--unstable",
"cli/bench/deno_http_native.js", "cli/bench/deno_http_native.js",
&server_addr(port), &server_addr(port),
], ],

View file

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

View file

@ -2414,4 +2414,33 @@ declare namespace Deno {
* ``` * ```
*/ */
export function fstat(rid: number): Promise<FileInfo>; 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>; 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( declare function fetch(

View file

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

View file

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