Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/head-page-fallthrough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Serve the page for a `HEAD` request when a route file exports both a page and a `GET` that returns nothing, such as a `[...404].tsx`. The server threw "did not return a response" and answered 500 instead of rendering the page as it does for `GET`.
10 changes: 10 additions & 0 deletions apps/tests/src/e2e/api-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ test.describe("api calls", () => {
expect(redirectResp.headers.get("x-shared-header")).toBe("event");
});

test("should serve the page for HEAD when the GET handler returns nothing", async () => {
// `[...404].tsx` exports a page and a `GET` that only answers JSON requests.
const get = await fetch("http://localhost:3000/no-such-page");
const head = await fetch("http://localhost:3000/no-such-page", { method: "HEAD" });

expect(get.status).toBe(404);
expect(head.status).toBe(get.status);
expect(head.headers.get("content-type")).toBe(get.headers.get("content-type"));
});

test("should preserve multiple Set-Cookie headers on redirect (RFC 6265)", async () => {
const response = await fetch("http://localhost:3000/api/multi-set-cookie-redirect", {
redirect: "manual",
Expand Down
4 changes: 3 additions & 1 deletion packages/start/src/server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export function createBaseHandler(
if (res !== undefined) {
return res;
}
if (event.request.method !== "GET") {
// A HEAD request runs the `GET` handler when there is no `HEAD` one,
// so it falls through to the page the same way a `GET` does.
if (event.request.method !== "GET" && event.request.method !== "HEAD") {
throw new Error(
`API handler for ${event.request.method} "${event.request.url}" did not return a response.`,
);
Expand Down
Loading