Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/non-post-early-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"capnweb": patch
---

Fix nodeHttpBatchRpcResponse leaving the connection open and crashing with
ERR_HTTP_HEADERS_SENT on non-POST requests. It now returns 405 immediately.
6 changes: 6 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,12 @@ describe("HTTP requests", () => {
expect(await Promise.all([promise1, promise2, promise3]))
.toStrictEqual([36, 5, 9]);
});

it("rejects non-POST requests with 405", async () => {
let response = await fetch(`http://${inject("testServerHost")}`, { method: "GET" });
expect(response.status).toBe(405);
await response.text();
});
});

describe("WebSockets", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export async function nodeHttpBatchRpcResponse(
}): Promise<void> {
if (request.method !== "POST") {
response.writeHead(405, "This endpoint only accepts POST requests.");
response.end();
return;
}

let body = await new Promise<string>((resolve, reject) => {
Expand Down
Loading