mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
chore(cli): Reduce port conflict in tests (#19988)
Ports are still occasionally causing CI flake -- allocate and separate ports further for fetch/http tests.
This commit is contained in:
parent
2fd87471e8
commit
43877f1209
2 changed files with 114 additions and 102 deletions
|
@ -10,7 +10,7 @@ import {
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
import { Buffer } from "../../../test_util/std/io/buffer.ts";
|
import { Buffer } from "../../../test_util/std/io/buffer.ts";
|
||||||
|
|
||||||
const listenPort = 4504;
|
const listenPort = 4506;
|
||||||
|
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
|
@ -1909,7 +1909,7 @@ Deno.test(
|
||||||
// https://github.com/denoland/deno/issues/18350
|
// https://github.com/denoland/deno/issues/18350
|
||||||
{ ignore: Deno.build.os === "windows", permissions: { net: true } },
|
{ ignore: Deno.build.os === "windows", permissions: { net: true } },
|
||||||
async function fetchRequestBodyErrorCatchable() {
|
async function fetchRequestBodyErrorCatchable() {
|
||||||
const listener = Deno.listen({ hostname: "127.0.0.1", port: 4514 });
|
const listener = Deno.listen({ hostname: "127.0.0.1", port: listenPort });
|
||||||
const server = (async () => {
|
const server = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
|
@ -1936,7 +1936,7 @@ Deno.test(
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await assertRejects(() =>
|
const err = await assertRejects(() =>
|
||||||
fetch("http://localhost:4514", {
|
fetch(`http://localhost:${listenPort}/`, {
|
||||||
body: stream,
|
body: stream,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,6 +14,9 @@ import {
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
import { join } from "../../../test_util/std/path/mod.ts";
|
import { join } from "../../../test_util/std/path/mod.ts";
|
||||||
|
|
||||||
|
const listenPort = 4507;
|
||||||
|
const listenPort2 = 4508;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
buildCaseInsensitiveCommaValueFinder,
|
buildCaseInsensitiveCommaValueFinder,
|
||||||
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||||
|
@ -25,7 +28,7 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
|
||||||
|
|
||||||
const w = new BufWriter(conn);
|
const w = new BufWriter(conn);
|
||||||
const r = new BufReader(conn);
|
const r = new BufReader(conn);
|
||||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||||
const writeResult = await w.write(encoder.encode(body));
|
const writeResult = await w.write(encoder.encode(body));
|
||||||
assertEquals(body.length, writeResult);
|
assertEquals(body.length, writeResult);
|
||||||
await w.flush();
|
await w.flush();
|
||||||
|
@ -49,21 +52,21 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
|
||||||
Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
|
Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
const reqEvent = await httpConn.nextRequest();
|
const reqEvent = await httpConn.nextRequest();
|
||||||
assert(reqEvent);
|
assert(reqEvent);
|
||||||
const { request, respondWith } = reqEvent;
|
const { request, respondWith } = reqEvent;
|
||||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
assertEquals(new URL(request.url).href, `http://127.0.0.1:${listenPort}/`);
|
||||||
assertEquals(await request.text(), "");
|
assertEquals(await request.text(), "");
|
||||||
await respondWith(
|
await respondWith(
|
||||||
new Response("Hello World", { headers: { "foo": "bar" } }),
|
new Response("Hello World", { headers: { "foo": "bar" } }),
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
headers: { "connection": "close" },
|
headers: { "connection": "close" },
|
||||||
});
|
});
|
||||||
const clone = resp.clone();
|
const clone = resp.clone();
|
||||||
|
@ -144,7 +147,7 @@ Deno.test(
|
||||||
async function httpServerGetRequestBody() {
|
async function httpServerGetRequestBody() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -155,11 +158,11 @@ Deno.test(
|
||||||
await respondWith(new Response("", { headers: {} }));
|
await respondWith(new Response("", { headers: {} }));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const conn = await Deno.connect({ port: 4501 });
|
const conn = await Deno.connect({ port: listenPort });
|
||||||
// Send GET request with a body + content-length.
|
// Send GET request with a body + content-length.
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const body =
|
const body =
|
||||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nContent-Length: 5\r\n\r\n12345`;
|
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\nContent-Length: 5\r\n\r\n12345`;
|
||||||
const writeResult = await conn.write(encoder.encode(body));
|
const writeResult = await conn.write(encoder.encode(body));
|
||||||
assertEquals(body.length, writeResult);
|
assertEquals(body.length, writeResult);
|
||||||
|
|
||||||
|
@ -184,7 +187,7 @@ Deno.test(
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -195,7 +198,7 @@ Deno.test(
|
||||||
await respondWith(new Response(stream.readable));
|
await respondWith(new Response(stream.readable));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/");
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||||
const respBody = await resp.text();
|
const respBody = await resp.text();
|
||||||
assertEquals("hello world", respBody);
|
assertEquals("hello world", respBody);
|
||||||
await promise;
|
await promise;
|
||||||
|
@ -214,7 +217,7 @@ Deno.test(
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
const evt = await httpConn.nextRequest();
|
const evt = await httpConn.nextRequest();
|
||||||
|
@ -225,14 +228,14 @@ Deno.test(
|
||||||
await respondWith(new Response(""));
|
await respondWith(new Response(""));
|
||||||
|
|
||||||
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
||||||
// request for url (https://localhost:4501/): connection closed before
|
// request for url (https://localhost:${listenPort}/): connection closed before
|
||||||
// message completed".
|
// message completed".
|
||||||
assertEquals(await httpConn.nextRequest(), null);
|
assertEquals(await httpConn.nextRequest(), null);
|
||||||
|
|
||||||
listener.close();
|
listener.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
body: stream.readable,
|
body: stream.readable,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "connection": "close" },
|
headers: { "connection": "close" },
|
||||||
|
@ -247,7 +250,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerStreamDuplex() {
|
async function httpServerStreamDuplex() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -260,7 +263,7 @@ Deno.test(
|
||||||
|
|
||||||
const ts = new TransformStream();
|
const ts = new TransformStream();
|
||||||
const writable = ts.writable.getWriter();
|
const writable = ts.writable.getWriter();
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: ts.readable,
|
body: ts.readable,
|
||||||
});
|
});
|
||||||
|
@ -285,8 +288,8 @@ Deno.test(
|
||||||
);
|
);
|
||||||
|
|
||||||
Deno.test({ permissions: { net: true } }, async function httpServerClose() {
|
Deno.test({ permissions: { net: true } }, async function httpServerClose() {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const client = await Deno.connect({ port: 4501 });
|
const client = await Deno.connect({ port: listenPort });
|
||||||
const httpConn = Deno.serveHttp(await listener.accept());
|
const httpConn = Deno.serveHttp(await listener.accept());
|
||||||
client.close();
|
client.close();
|
||||||
const evt = await httpConn.nextRequest();
|
const evt = await httpConn.nextRequest();
|
||||||
|
@ -298,8 +301,8 @@ Deno.test({ permissions: { net: true } }, async function httpServerClose() {
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerInvalidMethod() {
|
async function httpServerInvalidMethod() {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const client = await Deno.connect({ port: 4501 });
|
const client = await Deno.connect({ port: listenPort });
|
||||||
const httpConn = Deno.serveHttp(await listener.accept());
|
const httpConn = Deno.serveHttp(await listener.accept());
|
||||||
await client.write(new Uint8Array([1, 2, 3]));
|
await client.write(new Uint8Array([1, 2, 3]));
|
||||||
await assertRejects(
|
await assertRejects(
|
||||||
|
@ -319,7 +322,7 @@ Deno.test(
|
||||||
{ permissions: { read: true, net: true } },
|
{ permissions: { read: true, net: true } },
|
||||||
async function httpServerWithTls() {
|
async function httpServerWithTls() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listenTls({
|
const listener = Deno.listenTls({
|
||||||
|
@ -336,7 +339,7 @@ Deno.test(
|
||||||
await respondWith(new Response("Hello World"));
|
await respondWith(new Response("Hello World"));
|
||||||
|
|
||||||
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
||||||
// request for url (https://localhost:4501/): connection closed before
|
// request for url (https://localhost:${listenPort}/): connection closed before
|
||||||
// message completed".
|
// message completed".
|
||||||
assertEquals(await httpConn.nextRequest(), null);
|
assertEquals(await httpConn.nextRequest(), null);
|
||||||
|
|
||||||
|
@ -360,7 +363,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerRegressionHang() {
|
async function httpServerRegressionHang() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -372,7 +375,7 @@ Deno.test(
|
||||||
await respondWith(new Response("response"));
|
await respondWith(new Response("response"));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: "request",
|
body: "request",
|
||||||
});
|
});
|
||||||
|
@ -389,7 +392,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerCancelBodyOnResponseFailure() {
|
async function httpServerCancelBodyOnResponseFailure() {
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
const event = await httpConn.nextRequest();
|
const event = await httpConn.nextRequest();
|
||||||
|
@ -424,7 +427,7 @@ Deno.test(
|
||||||
listener.close();
|
listener.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/");
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||||
await resp.body!.cancel();
|
await resp.body!.cancel();
|
||||||
await promise;
|
await promise;
|
||||||
},
|
},
|
||||||
|
@ -434,7 +437,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerNextRequestErrorExposedInResponse() {
|
async function httpServerNextRequestErrorExposedInResponse() {
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
const event = await httpConn.nextRequest();
|
const event = await httpConn.nextRequest();
|
||||||
|
@ -469,7 +472,7 @@ Deno.test(
|
||||||
listener.close();
|
listener.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/");
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||||
await resp.body!.cancel();
|
await resp.body!.cancel();
|
||||||
await promise;
|
await promise;
|
||||||
},
|
},
|
||||||
|
@ -479,7 +482,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerEmptyBlobResponse() {
|
async function httpServerEmptyBlobResponse() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -489,7 +492,7 @@ Deno.test(
|
||||||
await respondWith(new Response(new Blob([])));
|
await respondWith(new Response(new Blob([])));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/");
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||||
const respBody = await resp.text();
|
const respBody = await resp.text();
|
||||||
assertEquals("", respBody);
|
assertEquals("", respBody);
|
||||||
await promise;
|
await promise;
|
||||||
|
@ -515,11 +518,11 @@ Deno.test(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const l = Deno.listen({ port: 4500 });
|
const l = Deno.listen({ port: listenPort });
|
||||||
serve(l);
|
serve(l);
|
||||||
|
|
||||||
await delay(300);
|
await delay(300);
|
||||||
const res = await fetch("http://localhost:4500/");
|
const res = await fetch(`http://localhost:${listenPort}/`);
|
||||||
const _text = await res.text();
|
const _text = await res.text();
|
||||||
|
|
||||||
// Close connection and listener.
|
// Close connection and listener.
|
||||||
|
@ -543,7 +546,7 @@ Deno.test(
|
||||||
const httpConns: Deno.HttpConn[] = [];
|
const httpConns: Deno.HttpConn[] = [];
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
for await (const conn of listener) {
|
for await (const conn of listener) {
|
||||||
(async () => {
|
(async () => {
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -560,7 +563,7 @@ Deno.test(
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const clientConn = await Deno.connect({ port: 4501 });
|
const clientConn = await Deno.connect({ port: listenPort });
|
||||||
|
|
||||||
const r1 = await writeRequestAndReadResponse(clientConn);
|
const r1 = await writeRequestAndReadResponse(clientConn);
|
||||||
assertEquals(r1, "hello");
|
assertEquals(r1, "hello");
|
||||||
|
@ -600,7 +603,7 @@ Deno.test(
|
||||||
|
|
||||||
const w = new BufWriter(conn);
|
const w = new BufWriter(conn);
|
||||||
const r = new BufReader(conn);
|
const r = new BufReader(conn);
|
||||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||||
const writeResult = await w.write(encoder.encode(body));
|
const writeResult = await w.write(encoder.encode(body));
|
||||||
assertEquals(body.length, writeResult);
|
assertEquals(body.length, writeResult);
|
||||||
await w.flush();
|
await w.flush();
|
||||||
|
@ -645,7 +648,7 @@ Deno.test(
|
||||||
}
|
}
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const finished = (async () => {
|
const finished = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -655,7 +658,7 @@ Deno.test(
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// start a client
|
// start a client
|
||||||
const clientConn = await Deno.connect({ port: 4501 });
|
const clientConn = await Deno.connect({ port: listenPort });
|
||||||
|
|
||||||
const r1 = await writeRequest(clientConn);
|
const r1 = await writeRequest(clientConn);
|
||||||
assertEquals(r1, "0\n1\n2\n");
|
assertEquals(r1, "0\n1\n2\n");
|
||||||
|
@ -673,7 +676,7 @@ Deno.test(
|
||||||
async function httpRequestLatin1Headers() {
|
async function httpRequestLatin1Headers() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -686,9 +689,9 @@ Deno.test(
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const clientConn = await Deno.connect({ port: 4501 });
|
const clientConn = await Deno.connect({ port: listenPort });
|
||||||
const requestText =
|
const requestText =
|
||||||
"GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nX-Header-Test: á\r\n\r\n";
|
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\nX-Header-Test: á\r\n\r\n`;
|
||||||
const requestBytes = new Uint8Array(requestText.length);
|
const requestBytes = new Uint8Array(requestText.length);
|
||||||
for (let i = 0; i < requestText.length; i++) {
|
for (let i = 0; i < requestText.length; i++) {
|
||||||
requestBytes[i] = requestText.charCodeAt(i);
|
requestBytes[i] = requestText.charCodeAt(i);
|
||||||
|
@ -721,7 +724,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerRequestWithoutPath() {
|
async function httpServerRequestWithoutPath() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
|
@ -729,12 +732,15 @@ Deno.test(
|
||||||
const reqEvent = await httpConn.nextRequest();
|
const reqEvent = await httpConn.nextRequest();
|
||||||
assert(reqEvent);
|
assert(reqEvent);
|
||||||
const { request, respondWith } = reqEvent;
|
const { request, respondWith } = reqEvent;
|
||||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
assertEquals(
|
||||||
|
new URL(request.url).href,
|
||||||
|
`http://127.0.0.1:${listenPort}/`,
|
||||||
|
);
|
||||||
assertEquals(await request.text(), "");
|
assertEquals(await request.text(), "");
|
||||||
await respondWith(new Response());
|
await respondWith(new Response());
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const clientConn = await Deno.connect({ port: 4501 });
|
const clientConn = await Deno.connect({ port: listenPort });
|
||||||
|
|
||||||
async function writeRequest(conn: Deno.Conn) {
|
async function writeRequest(conn: Deno.Conn) {
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
|
@ -742,7 +748,7 @@ Deno.test(
|
||||||
const w = new BufWriter(conn);
|
const w = new BufWriter(conn);
|
||||||
const r = new BufReader(conn);
|
const r = new BufReader(conn);
|
||||||
const body =
|
const body =
|
||||||
`CONNECT 127.0.0.1:4501 HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
`CONNECT 127.0.0.1:${listenPort} HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||||
const writeResult = await w.write(encoder.encode(body));
|
const writeResult = await w.write(encoder.encode(body));
|
||||||
assertEquals(body.length, writeResult);
|
assertEquals(body.length, writeResult);
|
||||||
await w.flush();
|
await w.flush();
|
||||||
|
@ -766,7 +772,7 @@ Deno.test(
|
||||||
|
|
||||||
Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
|
Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -786,7 +792,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const def = deferred();
|
const def = deferred();
|
||||||
const ws = new WebSocket("ws://localhost:4501");
|
const ws = new WebSocket(`ws://localhost:${listenPort}`);
|
||||||
ws.onmessage = (m) => assertEquals(m.data, "foo");
|
ws.onmessage = (m) => assertEquals(m.data, "foo");
|
||||||
ws.onerror = () => fail();
|
ws.onerror = () => fail();
|
||||||
ws.onclose = () => def.resolve();
|
ws.onclose = () => def.resolve();
|
||||||
|
@ -887,20 +893,23 @@ Deno.test(
|
||||||
async function httpCookieConcatenation() {
|
async function httpCookieConcatenation() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
const reqEvent = await httpConn.nextRequest();
|
const reqEvent = await httpConn.nextRequest();
|
||||||
assert(reqEvent);
|
assert(reqEvent);
|
||||||
const { request, respondWith } = reqEvent;
|
const { request, respondWith } = reqEvent;
|
||||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
assertEquals(
|
||||||
|
new URL(request.url).href,
|
||||||
|
`http://127.0.0.1:${listenPort}/`,
|
||||||
|
);
|
||||||
assertEquals(await request.text(), "");
|
assertEquals(await request.text(), "");
|
||||||
assertEquals(request.headers.get("cookie"), "foo=bar; bar=foo");
|
assertEquals(request.headers.get("cookie"), "foo=bar; bar=foo");
|
||||||
await respondWith(new Response("ok"));
|
await respondWith(new Response("ok"));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
headers: [
|
headers: [
|
||||||
["connection", "close"],
|
["connection", "close"],
|
||||||
["cookie", "foo=bar"],
|
["cookie", "foo=bar"],
|
||||||
|
@ -916,8 +925,8 @@ Deno.test(
|
||||||
|
|
||||||
// https://github.com/denoland/deno/issues/11651
|
// https://github.com/denoland/deno/issues/11651
|
||||||
Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
|
Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const client = await Deno.connect({ port: 4501 });
|
const client = await Deno.connect({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
|
||||||
|
@ -943,7 +952,7 @@ Deno.test(
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -952,7 +961,7 @@ Deno.test(
|
||||||
const f = await Deno.open(tmpFile, { read: true });
|
const f = await Deno.open(tmpFile, { read: true });
|
||||||
await respondWith(new Response(f.readable, { status: 200 }));
|
await respondWith(new Response(f.readable, { status: 200 }));
|
||||||
})();
|
})();
|
||||||
const resp = await fetch("http://127.0.0.1:4501/");
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||||
const body = await resp.arrayBuffer();
|
const body = await resp.arrayBuffer();
|
||||||
assertEquals(body.byteLength, 70 * 1024);
|
assertEquals(body.byteLength, 70 * 1024);
|
||||||
await promise;
|
await promise;
|
||||||
|
@ -964,9 +973,9 @@ Deno.test(
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { net: true, write: true, read: true } },
|
{ permissions: { net: true, write: true, read: true } },
|
||||||
async function httpServerClosedStream() {
|
async function httpServerClosedStream() {
|
||||||
const listener = Deno.listen({ port: 4502 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
|
|
||||||
const client = await Deno.connect({ port: 4502 });
|
const client = await Deno.connect({ port: listenPort });
|
||||||
await client.write(new TextEncoder().encode(
|
await client.write(new TextEncoder().encode(
|
||||||
`GET / HTTP/1.0\r\n\r\n`,
|
`GET / HTTP/1.0\r\n\r\n`,
|
||||||
));
|
));
|
||||||
|
@ -1006,9 +1015,9 @@ Deno.test(
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerIncompleteMessage() {
|
async function httpServerIncompleteMessage() {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
|
|
||||||
const client = await Deno.connect({ port: 4501 });
|
const client = await Deno.connect({ port: listenPort });
|
||||||
await client.write(new TextEncoder().encode(
|
await client.write(new TextEncoder().encode(
|
||||||
`GET / HTTP/1.0\r\n\r\n`,
|
`GET / HTTP/1.0\r\n\r\n`,
|
||||||
));
|
));
|
||||||
|
@ -1053,17 +1062,17 @@ Deno.test(
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerDoesntLeakResources() {
|
async function httpServerDoesntLeakResources() {
|
||||||
const listener = Deno.listen({ port: 4505 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const [conn, clientConn] = await Promise.all([
|
const [conn, clientConn] = await Promise.all([
|
||||||
listener.accept(),
|
listener.accept(),
|
||||||
Deno.connect({ port: 4505 }),
|
Deno.connect({ port: listenPort }),
|
||||||
]);
|
]);
|
||||||
const httpConn = Deno.serveHttp(conn);
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
httpConn.nextRequest(),
|
httpConn.nextRequest(),
|
||||||
clientConn.write(new TextEncoder().encode(
|
clientConn.write(new TextEncoder().encode(
|
||||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:4505\r\n\r\n`,
|
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`,
|
||||||
)),
|
)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -1081,11 +1090,14 @@ Deno.test(
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
|
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
listener = Deno.listen({ port: 4508 });
|
listener = Deno.listen({ port: listenPort });
|
||||||
for await (const conn of listener) {
|
for await (const conn of listener) {
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
for await (const { request, respondWith } of httpConn) {
|
for await (const { request, respondWith } of httpConn) {
|
||||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4508/");
|
assertEquals(
|
||||||
|
new URL(request.url).href,
|
||||||
|
`http://127.0.0.1:${listenPort}/`,
|
||||||
|
);
|
||||||
// not reading request body on purpose
|
// not reading request body on purpose
|
||||||
respondWith(new Response("ok"));
|
respondWith(new Response("ok"));
|
||||||
}
|
}
|
||||||
|
@ -1093,7 +1105,7 @@ Deno.test(
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resourcesBefore = Deno.resources();
|
const resourcesBefore = Deno.resources();
|
||||||
const response = await fetch("http://127.0.0.1:4508", {
|
const response = await fetch(`http://127.0.0.1:${listenPort}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: "hello world",
|
body: "hello world",
|
||||||
});
|
});
|
||||||
|
@ -1151,7 +1163,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpConnConcurrentNextRequestCalls() {
|
async function httpConnConcurrentNextRequestCalls() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -1189,7 +1201,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpConnAutoCloseDelayedOnUpgrade() {
|
async function httpConnAutoCloseDelayedOnUpgrade() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
async function server() {
|
async function server() {
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -1234,7 +1246,7 @@ Deno.test(
|
||||||
{ permissions: { net: true, run: true } },
|
{ permissions: { net: true, run: true } },
|
||||||
async function httpServerDeleteRequestHasBody() {
|
async function httpServerDeleteRequestHasBody() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -1268,7 +1280,7 @@ Deno.test(
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async function httpServerRespondNonAsciiUint8Array() {
|
async function httpServerRespondNonAsciiUint8Array() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
|
@ -1282,7 +1294,7 @@ Deno.test(
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://localhost:4501/");
|
const resp = await fetch(`http://localhost:${listenPort}/`);
|
||||||
assertEquals(resp.status, 200);
|
assertEquals(resp.status, 200);
|
||||||
const body = await resp.arrayBuffer();
|
const body = await resp.arrayBuffer();
|
||||||
assertEquals(new Uint8Array(body), new Uint8Array([128]));
|
assertEquals(new Uint8Array(body), new Uint8Array([128]));
|
||||||
|
@ -1350,7 +1362,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
|
||||||
const data = { hello: "deno", now: "with", compressed: "body" };
|
const data = { hello: "deno", now: "with", compressed: "body" };
|
||||||
|
@ -1402,7 +1414,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
|
||||||
const data = { hello: "deno", now: "with", compressed: "body" };
|
const data = { hello: "deno", now: "with", compressed: "body" };
|
||||||
|
@ -1459,7 +1471,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1512,7 +1524,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1568,7 +1580,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1621,7 +1633,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1681,7 +1693,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1740,7 +1752,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1796,7 +1808,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
async function server() {
|
async function server() {
|
||||||
|
@ -1852,7 +1864,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -1914,7 +1926,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -1980,7 +1992,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
let contentLength: string;
|
let contentLength: string;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
|
@ -2046,7 +2058,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
let contentLength: string;
|
let contentLength: string;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
|
@ -2108,7 +2120,7 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
let contentLength: string;
|
let contentLength: string;
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
|
@ -2165,7 +2177,7 @@ Deno.test({
|
||||||
|
|
||||||
Deno.test("upgradeHttp tcp", async () => {
|
Deno.test("upgradeHttp tcp", async () => {
|
||||||
async function client() {
|
async function client() {
|
||||||
const tcpConn = await Deno.connect({ port: 4501 });
|
const tcpConn = await Deno.connect({ port: listenPort });
|
||||||
await tcpConn.write(
|
await tcpConn.write(
|
||||||
new TextEncoder().encode(
|
new TextEncoder().encode(
|
||||||
"CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n",
|
"CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n",
|
||||||
|
@ -2201,7 +2213,7 @@ Deno.test("upgradeHttp tcp", async () => {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return new Response(null, { status: 101 });
|
return new Response(null, { status: 101 });
|
||||||
}, { port: 4501, signal });
|
}, { port: listenPort, signal });
|
||||||
|
|
||||||
await Promise.all([server, client()]);
|
await Promise.all([server, client()]);
|
||||||
});
|
});
|
||||||
|
@ -2216,7 +2228,7 @@ Deno.test(
|
||||||
];
|
];
|
||||||
const tlsConn = await Deno.connectTls({
|
const tlsConn = await Deno.connectTls({
|
||||||
hostname: "localhost",
|
hostname: "localhost",
|
||||||
port: 4502,
|
port: listenPort,
|
||||||
caCerts,
|
caCerts,
|
||||||
});
|
});
|
||||||
await tlsConn.write(
|
await tlsConn.write(
|
||||||
|
@ -2256,7 +2268,7 @@ Deno.test(
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return new Response(null, { status: 101 });
|
return new Response(null, { status: 101 });
|
||||||
}, { hostname: "localhost", port: 4502, signal, keyFile, certFile });
|
}, { hostname: "localhost", port: listenPort, signal, keyFile, certFile });
|
||||||
|
|
||||||
await Promise.all([server, client()]);
|
await Promise.all([server, client()]);
|
||||||
},
|
},
|
||||||
|
@ -2329,7 +2341,7 @@ Deno.test(
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -2340,7 +2352,7 @@ Deno.test(
|
||||||
await respondWith(new Response(body));
|
await respondWith(new Response(body));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "connection": "close" },
|
headers: { "connection": "close" },
|
||||||
body,
|
body,
|
||||||
|
@ -2376,7 +2388,7 @@ Deno.test(
|
||||||
|
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -2387,7 +2399,7 @@ Deno.test(
|
||||||
await respondWith(new Response(body));
|
await respondWith(new Response(body));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "connection": "close" },
|
headers: { "connection": "close" },
|
||||||
body: stream.readable,
|
body: stream.readable,
|
||||||
|
@ -2405,7 +2417,7 @@ Deno.test(
|
||||||
permissions: { net: true },
|
permissions: { net: true },
|
||||||
},
|
},
|
||||||
async function httpServerWithoutExclusiveAccessToTcp() {
|
async function httpServerWithoutExclusiveAccessToTcp() {
|
||||||
const port = 4506;
|
const port = listenPort;
|
||||||
const listener = Deno.listen({ port });
|
const listener = Deno.listen({ port });
|
||||||
|
|
||||||
const [clientConn, serverConn] = await Promise.all([
|
const [clientConn, serverConn] = await Promise.all([
|
||||||
|
@ -2429,7 +2441,7 @@ Deno.test(
|
||||||
},
|
},
|
||||||
async function httpServerWithoutExclusiveAccessToTls() {
|
async function httpServerWithoutExclusiveAccessToTls() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4507;
|
const port = listenPort;
|
||||||
const listener = Deno.listenTls({
|
const listener = Deno.listenTls({
|
||||||
hostname,
|
hostname,
|
||||||
port,
|
port,
|
||||||
|
@ -2485,7 +2497,7 @@ Deno.test(
|
||||||
async function httpServerRequestResponseClone() {
|
async function httpServerRequestResponseClone() {
|
||||||
const body = "deno".repeat(64 * 1024);
|
const body = "deno".repeat(64 * 1024);
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
|
@ -2524,7 +2536,7 @@ Deno.test(
|
||||||
await respondWith(new Response(body));
|
await respondWith(new Response(body));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const response = await fetch("http://localhost:4501", {
|
const response = await fetch(`http://localhost:${listenPort}`, {
|
||||||
body,
|
body,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
@ -2541,8 +2553,8 @@ Deno.test({
|
||||||
permissions: { net: true, run: true },
|
permissions: { net: true, run: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
const port2 = 4502;
|
const port2 = listenPort2;
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
|
@ -2674,7 +2686,7 @@ for (const compression of [true, false]) {
|
||||||
permissions: { net: true },
|
permissions: { net: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
const server = httpServerWithErrorBody(listener, compression);
|
const server = httpServerWithErrorBody(listener, compression);
|
||||||
|
@ -2707,7 +2719,7 @@ for (const compression of [true, false]) {
|
||||||
permissions: { net: true },
|
permissions: { net: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const listener = Deno.listen({ hostname, port });
|
const listener = Deno.listen({ hostname, port });
|
||||||
const server = httpServerWithErrorBody(listener, compression);
|
const server = httpServerWithErrorBody(listener, compression);
|
||||||
|
@ -2734,7 +2746,7 @@ for (const compression of [true, false]) {
|
||||||
permissions: { net: true, read: true },
|
permissions: { net: true, read: true },
|
||||||
async fn() {
|
async fn() {
|
||||||
const hostname = "localhost";
|
const hostname = "localhost";
|
||||||
const port = 4501;
|
const port = listenPort;
|
||||||
|
|
||||||
const listener = Deno.listenTls({
|
const listener = Deno.listenTls({
|
||||||
hostname,
|
hostname,
|
||||||
|
@ -2770,7 +2782,7 @@ Deno.test({
|
||||||
async fn() {
|
async fn() {
|
||||||
let httpConn: Deno.HttpConn;
|
let httpConn: Deno.HttpConn;
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: listenPort });
|
||||||
const conn = await listener.accept();
|
const conn = await listener.accept();
|
||||||
listener.close();
|
listener.close();
|
||||||
httpConn = Deno.serveHttp(conn);
|
httpConn = Deno.serveHttp(conn);
|
||||||
|
@ -2784,7 +2796,7 @@ Deno.test({
|
||||||
|
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
|
|
||||||
fetch("http://127.0.0.1:4501/", {
|
fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||||
signal: abortController.signal,
|
signal: abortController.signal,
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
Loading…
Add table
Reference in a new issue