mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(ext/node): http2.createServer (#22708)
This commit is contained in:
parent
0fb67ce43e
commit
588dd5e669
5 changed files with 1034 additions and 241 deletions
File diff suppressed because it is too large
Load diff
|
@ -2248,6 +2248,16 @@ export class ERR_FALSY_VALUE_REJECTION extends NodeError {
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS extends NodeError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS",
|
||||||
|
"Number of custom settings exceeds MAX_ADDITIONAL_SETTINGS",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class ERR_HTTP2_INVALID_SETTING_VALUE extends NodeRangeError {
|
export class ERR_HTTP2_INVALID_SETTING_VALUE extends NodeRangeError {
|
||||||
actual: unknown;
|
actual: unknown;
|
||||||
min?: number;
|
min?: number;
|
||||||
|
|
|
@ -8,6 +8,8 @@ import {
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertStringIncludes,
|
assertStringIncludes,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
|
curlRequest,
|
||||||
|
curlRequestWithStdErr,
|
||||||
execCode,
|
execCode,
|
||||||
fail,
|
fail,
|
||||||
tmpUnixSocketPath,
|
tmpUnixSocketPath,
|
||||||
|
@ -3793,32 +3795,6 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
async function curlRequest(args: string[]) {
|
|
||||||
const { success, stdout, stderr } = await new Deno.Command("curl", {
|
|
||||||
args,
|
|
||||||
stdout: "piped",
|
|
||||||
stderr: "piped",
|
|
||||||
}).output();
|
|
||||||
assert(
|
|
||||||
success,
|
|
||||||
`Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
|
|
||||||
);
|
|
||||||
return new TextDecoder().decode(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function curlRequestWithStdErr(args: string[]) {
|
|
||||||
const { success, stdout, stderr } = await new Deno.Command("curl", {
|
|
||||||
args,
|
|
||||||
stdout: "piped",
|
|
||||||
stderr: "piped",
|
|
||||||
}).output();
|
|
||||||
assert(
|
|
||||||
success,
|
|
||||||
`Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
|
|
||||||
);
|
|
||||||
return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)];
|
|
||||||
}
|
|
||||||
|
|
||||||
Deno.test("Deno.HttpServer is not thenable", async () => {
|
Deno.test("Deno.HttpServer is not thenable", async () => {
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function serveTest() {
|
async function serveTest() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import * as colors from "@std/fmt/colors.ts";
|
import * as colors from "@std/fmt/colors.ts";
|
||||||
|
import { assert } from "@std/assert/mod.ts";
|
||||||
export { colors };
|
export { colors };
|
||||||
import { join, resolve } from "@std/path/mod.ts";
|
import { join, resolve } from "@std/path/mod.ts";
|
||||||
export {
|
export {
|
||||||
|
@ -85,3 +86,35 @@ export function tmpUnixSocketPath(): string {
|
||||||
const folder = Deno.makeTempDirSync();
|
const folder = Deno.makeTempDirSync();
|
||||||
return join(folder, "socket");
|
return join(folder, "socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function curlRequest(args: string[]) {
|
||||||
|
const { success, stdout, stderr } = await new Deno.Command("curl", {
|
||||||
|
args,
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "piped",
|
||||||
|
}).output();
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
assert(
|
||||||
|
success,
|
||||||
|
`Failed to cURL ${args}: stdout\n\n${
|
||||||
|
decoder.decode(stdout)
|
||||||
|
}\n\nstderr:\n\n${decoder.decode(stderr)}`,
|
||||||
|
);
|
||||||
|
return decoder.decode(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function curlRequestWithStdErr(args: string[]) {
|
||||||
|
const { success, stdout, stderr } = await new Deno.Command("curl", {
|
||||||
|
args,
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "piped",
|
||||||
|
}).output();
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
assert(
|
||||||
|
success,
|
||||||
|
`Failed to cURL ${args}: stdout\n\n${
|
||||||
|
decoder.decode(stdout)
|
||||||
|
}\n\nstderr:\n\n${decoder.decode(stderr)}`,
|
||||||
|
);
|
||||||
|
return [decoder.decode(stdout), decoder.decode(stderr)];
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import * as http2 from "node:http2";
|
import * as http2 from "node:http2";
|
||||||
import * as net from "node:net";
|
import * as net from "node:net";
|
||||||
import { assert, assertEquals } from "@std/assert/mod.ts";
|
import { assert, assertEquals } from "@std/assert/mod.ts";
|
||||||
|
import { curlRequest } from "../unit/test_util.ts";
|
||||||
|
|
||||||
for (const url of ["http://127.0.0.1:4246", "https://127.0.0.1:4247"]) {
|
for (const url of ["http://127.0.0.1:4246", "https://127.0.0.1:4247"]) {
|
||||||
Deno.test(`[node/http2 client] ${url}`, {
|
Deno.test(`[node/http2 client] ${url}`, {
|
||||||
|
@ -108,35 +109,6 @@ Deno.test(`[node/http2 client createConnection]`, {
|
||||||
assertEquals(receivedData, "hello world\n");
|
assertEquals(receivedData, "hello world\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO(bartlomieju): reenable sanitizers
|
|
||||||
Deno.test("[node/http2 server]", { sanitizeOps: false }, async () => {
|
|
||||||
const server = http2.createServer();
|
|
||||||
server.listen(0);
|
|
||||||
const port = (<net.AddressInfo> server.address()).port;
|
|
||||||
const sessionPromise = new Promise<http2.Http2Session>((resolve) =>
|
|
||||||
server.on("session", resolve)
|
|
||||||
);
|
|
||||||
|
|
||||||
const responsePromise = fetch(`http://localhost:${port}/path`, {
|
|
||||||
method: "POST",
|
|
||||||
body: "body",
|
|
||||||
});
|
|
||||||
|
|
||||||
const session = await sessionPromise;
|
|
||||||
const stream = await new Promise<http2.ServerHttp2Stream>((resolve) =>
|
|
||||||
session.on("stream", resolve)
|
|
||||||
);
|
|
||||||
await new Promise((resolve) => stream.on("headers", resolve));
|
|
||||||
await new Promise((resolve) => stream.on("data", resolve));
|
|
||||||
await new Promise((resolve) => stream.on("end", resolve));
|
|
||||||
stream.respond();
|
|
||||||
stream.end();
|
|
||||||
const resp = await responsePromise;
|
|
||||||
await resp.text();
|
|
||||||
|
|
||||||
await new Promise((resolve) => server.close(resolve));
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test("[node/http2 client GET https://www.example.com]", async () => {
|
Deno.test("[node/http2 client GET https://www.example.com]", async () => {
|
||||||
const clientSession = http2.connect("https://www.example.com");
|
const clientSession = http2.connect("https://www.example.com");
|
||||||
const req = clientSession.request({
|
const req = clientSession.request({
|
||||||
|
@ -165,3 +137,30 @@ Deno.test("[node/http2 client GET https://www.example.com]", async () => {
|
||||||
assertEquals(status, 200);
|
assertEquals(status, 200);
|
||||||
assert(chunk.length > 0);
|
assert(chunk.length > 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("[node/http2.createServer()]", {
|
||||||
|
// TODO(satyarohith): enable the test on windows.
|
||||||
|
ignore: Deno.build.os === "windows",
|
||||||
|
}, async () => {
|
||||||
|
const server = http2.createServer((_req, res) => {
|
||||||
|
res.setHeader("Content-Type", "text/html");
|
||||||
|
res.setHeader("X-Foo", "bar");
|
||||||
|
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
res.write("Hello, World!");
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
server.listen(0);
|
||||||
|
const port = (<net.AddressInfo> server.address()).port;
|
||||||
|
const endpoint = `http://localhost:${port}`;
|
||||||
|
|
||||||
|
const response = await curlRequest([
|
||||||
|
endpoint,
|
||||||
|
"--http2-prior-knowledge",
|
||||||
|
]);
|
||||||
|
assertEquals(response, "Hello, World!");
|
||||||
|
server.close();
|
||||||
|
// Wait to avoid leaking the timer from here
|
||||||
|
// https://github.com/denoland/deno/blob/749b6e45e58ac87188027f79fe403d130f86bd73/ext/node/polyfills/net.ts#L2396-L2402
|
||||||
|
// Issue: https://github.com/denoland/deno/issues/22764
|
||||||
|
await new Promise<void>((resolve) => server.on("close", resolve));
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue