diff --git a/cli/bench/deno_http_native.js b/cli/bench/deno_http_native.js index fa779be211..57c19b4b9e 100644 --- a/cli/bench/deno_http_native.js +++ b/cli/bench/deno_http_native.js @@ -9,7 +9,7 @@ const body = Deno.core.encode("Hello World"); for await (const conn of listener) { (async () => { - const requests = Deno.startHttp(conn); + const requests = Deno.serveHttp(conn); for await (const { respondWith } of requests) { respondWith(new Response(body)); } diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 9dbe6817f1..91e6825b01 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1211,18 +1211,20 @@ declare namespace Deno { /** **UNSTABLE**: new API, yet to be vetted. * - * Parse HTTP requests from the given connection + * Services HTTP requests given a TCP or TLS socket. * * ```ts - * const httpConn = await Deno.startHttp(conn); - * const { request, respondWith } = await httpConn.next(); - * respondWith(new Response("Hello World")); + * const httpConn = Deno.serveHttp(conn); + * const e = await httpConn.nextRequest(); + * if (e) { + * e.respondWith(new Response("Hello World")); + * } * ``` * - * If `httpConn.next()` encounters an error or returns `done == true` then - * the underlying HttpConn resource is closed automatically. + * If `httpConn.nextRequest()` encounters an error or returns `null` + * then the underlying HttpConn resource is closed automatically. */ - export function startHttp(conn: Conn): HttpConn; + export function serveHttp(conn: Conn): HttpConn; } declare function fetch( diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index fc85301426..77af953e9c 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -12,7 +12,7 @@ unitTest({ perms: { net: true } }, async function httpServerBasic() { const promise = (async () => { const listener = Deno.listen({ port: 4501 }); for await (const conn of listener) { - const httpConn = Deno.startHttp(conn); + const httpConn = Deno.serveHttp(conn); for await (const { request, respondWith } of httpConn) { assertEquals(await request.text(), ""); respondWith(new Response("Hello World")); @@ -41,7 +41,7 @@ unitTest( const promise = (async () => { const listener = Deno.listen({ port: 4501 }); const conn = await listener.accept(); - const httpConn = Deno.startHttp(conn); + const httpConn = Deno.serveHttp(conn); const evt = await httpConn.nextRequest(); assert(evt); const { request, respondWith } = evt; @@ -70,7 +70,7 @@ unitTest( const promise = (async () => { const listener = Deno.listen({ port: 4501 }); const conn = await listener.accept(); - const httpConn = Deno.startHttp(conn); + const httpConn = Deno.serveHttp(conn); const evt = await httpConn.nextRequest(); assert(evt); const { request, respondWith } = evt; @@ -101,7 +101,7 @@ unitTest({ perms: { net: true } }, async function httpServerStreamDuplex() { const promise = (async () => { const listener = Deno.listen({ port: 4501 }); const conn = await listener.accept(); - const httpConn = Deno.startHttp(conn); + const httpConn = Deno.serveHttp(conn); const evt = await httpConn.nextRequest(); assert(evt); const { request, respondWith } = evt; @@ -136,7 +136,7 @@ unitTest({ perms: { net: true } }, async function httpServerStreamDuplex() { unitTest({ perms: { net: true } }, async function httpServerClose() { const listener = Deno.listen({ port: 4501 }); const client = await Deno.connect({ port: 4501 }); - const httpConn = Deno.startHttp(await listener.accept()); + const httpConn = Deno.serveHttp(await listener.accept()); client.close(); const evt = await httpConn.nextRequest(); assertEquals(evt, null); @@ -147,7 +147,7 @@ unitTest({ perms: { net: true } }, async function httpServerClose() { unitTest({ perms: { net: true } }, async function httpServerInvalidMethod() { const listener = Deno.listen({ port: 4501 }); const client = await Deno.connect({ port: 4501 }); - const httpConn = Deno.startHttp(await listener.accept()); + const httpConn = Deno.serveHttp(await listener.accept()); await client.write(new Uint8Array([1, 2, 3])); await assertThrowsAsync( async () => { @@ -175,7 +175,7 @@ unitTest( keyFile: "cli/tests/tls/localhost.key", }); const conn = await listener.accept(); - const httpConn = Deno.startHttp(conn); + const httpConn = Deno.serveHttp(conn); const evt = await httpConn.nextRequest(); assert(evt); const { request, respondWith } = evt; diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js index cfb015edd7..dd6c99a2d8 100644 --- a/runtime/js/40_http.js +++ b/runtime/js/40_http.js @@ -18,7 +18,7 @@ return entries; } - function startHttp(conn) { + function serveHttp(conn) { const rid = Deno.core.jsonOpSync("op_http_start", conn.rid); return new HttpConn(rid); } @@ -205,6 +205,6 @@ } window.__bootstrap.http = { - startHttp, + serveHttp, }; })(this); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 84eb69ef06..c240d1ea28 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -120,7 +120,7 @@ listen: __bootstrap.netUnstable.listen, connect: __bootstrap.netUnstable.connect, listenDatagram: __bootstrap.netUnstable.listenDatagram, - startHttp: __bootstrap.http.startHttp, + serveHttp: __bootstrap.http.serveHttp, startTls: __bootstrap.tls.startTls, fstatSync: __bootstrap.fs.fstatSync, fstat: __bootstrap.fs.fstat,