Skip to content

Commit 97f09f4

Browse files
committed
fix(start-server-core): guard against undefined ctx.response in HEAD fallback
If a fallback GET/ANY handler exits without returning a Response, ctx.response is undefined. Without the guard, handleRedirectResponse passes undefined through and new Response(null, undefined) silently synthesizes a 200 OK, masking the handler bug. Calling throwRouteHandlerError() surfaces the mistake with the same error used everywhere else in the file. Also removes the unsafe cast -- TypeScript narrows the type correctly after the never-returning guard.
1 parent 0d3549e commit 97f09f4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎packages/start-server-core/src/createStartHandler.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ async function handleServerRoutes({
903903
// Priority for HEAD: explicit HEAD handler → GET → ANY (last resort).
904904
const handler =
905905
requestMethod === 'HEAD'
906-
? (handlers['HEAD'] ?? handlers['GET'] ?? handlers['ANY'])
907-
: (handlers[requestMethod] ?? handlers['ANY'])
906+
? handlers['HEAD'] ?? handlers['GET'] ?? handlers['ANY']
907+
: handlers[requestMethod] ?? handlers['ANY']
908908
isHeadFallback =
909909
requestMethod === 'HEAD' && handler !== undefined && !handlers['HEAD']
910910

@@ -942,8 +942,12 @@ async function handleServerRoutes({
942942
// RFC 9110 §9.3.2: HEAD must carry the same header fields as GET but no body.
943943
// Resolve any redirect before stripping so the Location header survives.
944944
if (isHeadFallback) {
945+
if (!ctx.response) {
946+
throwRouteHandlerError()
947+
}
948+
945949
const resolved = await handleRedirectResponse(
946-
ctx.response as Response,
950+
ctx.response,
947951
request,
948952
getRouter,
949953
)

0 commit comments

Comments
 (0)