Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
boronine committed Nov 3, 2024
1 parent 8b5ae7a commit 2e741b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
31 changes: 30 additions & 1 deletion src/h2tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TunnelServer,
} from "./h2tunnel.js";
import net from "node:net";
import * as http2 from "node:http2";

// localhost HTTP1 server "python3 -m http.server"
const LOCAL_PORT = 14000;
Expand Down Expand Up @@ -422,7 +423,7 @@ await test(
},
);

await test.only("happy-path", { timeout: 5000 }, async (t) => {
await test("happy-path", { timeout: 5000 }, async (t) => {
const echo = new EchoServer(LOCAL_PORT, PROXY_PORT);
await echo.startAndWaitUntilReady();

Expand Down Expand Up @@ -545,3 +546,31 @@ await test("garbage-to-server", { timeout: 5000 }, async (t: TestContext) => {
await server.stop();
await echoServer.stopAndWaitUntilClosed();
});

// await test.only("http2", { timeout: 5000 }, async (t: TestContext) => {
// const server = http2.createServer();
// server.on("stream", (serverStream) => {
// serverStream.on("data", (chunk) =>
// console.log("got data", chunk.toString("utf-8")),
// );
// serverStream.on("error", (error) => {
// console.log("error", error);
// });
// serverStream.on("close", () => {
// console.log("close");
// });
// serverStream.on("end", () => {
// console.log("end");
// });
// });
// server.listen(16000, () => {
// const session = http2.connect(`http://localhost:${16000}`);
// session.on("connect", () => {
// const clientStream = session.request({
// [http2.constants.HTTP2_HEADER_METHOD]: "POST",
// });
// clientStream.write("a");
// clientStream.close(http2.constants.NGHTTP2_INTERNAL_ERROR);
// });
// });
// });
6 changes: 3 additions & 3 deletions src/h2tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ export abstract class AbstractTunnel<
log({ [tag]: "end" });
// 'end' comes before 'error', so we need to wait make sure 'error' doesn't come it before processing 'end'
// https://github.com/nodejs/node/issues/39400
endTimeout = setTimeout(() => {
setImmediate(() => {
if (!duplex2.writableEnded) {
log({ [tag]: "closing opposite" });
duplex2.end();
}
}, 50);
});
});

duplex1.on("close", () => {
log({ [tag]: "close" });
if (duplex1.errored && !duplex2.destroyed) {
if (duplex1.errored && !duplex2.closed) {
if (endTimeout) {
clearTimeout(endTimeout);
}
Expand Down

0 comments on commit 2e741b6

Please sign in to comment.