summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2021-04-09 11:54:27 -0400
committerGitHub <noreply@github.com>2021-04-09 11:54:27 -0400
commitc6e7a243d524417fe77c4799a2bcc1b3db1bf01a (patch)
tree7a0a88bf36c6f4cdc8ddfe4beb7e3c917b8a8352 /cli
parentcd0560210aa0ac9dc9772cdddcb1c5a59cef1815 (diff)
API change: Deno.startHttp -> Deno.serveHttp (#10087)
Diffstat (limited to 'cli')
-rw-r--r--cli/bench/deno_http_native.js2
-rw-r--r--cli/dts/lib.deno.unstable.d.ts16
-rw-r--r--cli/tests/unit/http_test.ts14
3 files changed, 17 insertions, 15 deletions
diff --git a/cli/bench/deno_http_native.js b/cli/bench/deno_http_native.js
index fa779be21..57c19b4b9 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 9dbe6817f..91e6825b0 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 fc8530142..77af953e9 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;