Content-Type missing when returning new Response with 404 status #8627
Labels
- P2: has workaround
Bug, but has workaround (priority)
feat: error pages
Related to 404 and 500 handling (scope)
requires refactor
Bug, may take longer as fixing either requires refactors, breaking changes, or considering tradeoffs
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Declaring a dynamic route like
/[param1]/[param2]
, if there is a returnnew Response(null, { status: 404 })
due to any reason in that route, the server side rendering of the404.astro
page happens but the Content-Type is missing.I've the security header
X-Content-Type-Options: nosniff
which check the presence of the Content-Type, breaking the rendering of the 404 by the browser. Removing the header, the 404 page is rendered successfully.Also, I've noticed the middleware I have adding the security header is executed twice in this case:
The first time, it doesn't contains the Content-Type but the second one yes. I think the browser is receiving the first one.
This is the use case we have in our application but probably it can be reproduced with other routes if a
new Response
is returned.It has been tested building and running the server with a NodeJS adapter, all routes with SSR:
npm run build && node dist/server/entry.mjs
. Stackblitz is responding with error too for this use case but the response is a bit different:I think the right fix is having the Content-Type and/or stop processing the request twice. If anyone prefer a Github repository instead of the stackblitz one, let me know. Thank you for your help!
What's the expected result?
The http response after returning a
Response
object by any route should have the Content-Type header.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-g7nwcp
Participation
The text was updated successfully, but these errors were encountered: