-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[turbopack]: Fix HEAD requests #50366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,7 +240,7 @@ export async function makeResolver( | |
return async function resolveRoute( | ||
_req: IncomingMessage, | ||
_res: ServerResponse | ||
) { | ||
): Promise<RouteResult | void> { | ||
const req = new NodeNextRequest(_req) | ||
const res = new NodeNextResponse(_res) | ||
const parsedUrl = url.parse(req.url!, true) | ||
|
@@ -250,15 +250,28 @@ export async function makeResolver( | |
|
||
await router.execute(req, res, parsedUrl) | ||
|
||
if (!res.originalResponse.headersSent) { | ||
res.setHeader('x-nextjs-route-result', '1') | ||
const routeResult: RouteResult = routeResults.get(req) ?? { | ||
type: 'none', | ||
} | ||
// If the headers are sent, then this was handled by middleware and there's | ||
// nothing for us to do. | ||
if (res.originalResponse.headersSent) { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it gets to this point, then middleware would have fully handled the response before the |
||
} | ||
|
||
res.body(JSON.stringify(routeResult)).send() | ||
// The response won't be used, but we need to close the request so that the | ||
// ClientResponse's promise will resolve. We signal that this response is | ||
// unneeded via the header. | ||
res.setHeader('x-nextjs-route-result', '1') | ||
res.send() | ||
|
||
// If we have a routeResult, then we hit the catchAllRoute during execution | ||
// and this is a rewrite request. | ||
const routeResult = routeResults.get(req) | ||
if (routeResult) { | ||
routeResults.delete(req) | ||
return routeResult | ||
} | ||
|
||
routeResults.delete(req) | ||
// Finally, if the catchall didn't match, than this request is invalid | ||
// (maybe they're missing the basePath?) | ||
return { type: 'none' } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was erroring out for HEAD requests, because the
clientResponse
always has an empty body.