mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
1a468dd0cd
* fix: apply headers, cookies, and status set by getServerSideProps to the response getServerSideProps receives a res object that supports setHeader(), statusCode, and end(). Previously, any headers, cookies, or status codes set on this object were silently discarded in the final HTML response. This fixes two code paths: 1. Production (index.ts renderPage): Capture the res object from createReqRes and merge its accumulated headers, cookies, and status into the final Response. Also handle the short-circuit case where gSSP calls res.end() directly. 2. Dev server (dev-server.ts): Preserve res.statusCode set by gSSP so it flows through to streamPageToResponse. Also detect when gSSP calls res.end() to avoid writing to an already-ended stream. Added getHeaders() and headersSent to the mock res object in createReqRes so callers can read accumulated response metadata. Test: Added fixture pages (ssr-headers.tsx, ssr-res-end.tsx) and integration tests verifying custom headers, cookies, status codes, and res.end() short-circuit behavior. * refactor: explicitly forward gSSP headers in dev server Address review feedback: - Capture headers newly set by gSSP via snapshot/diff and forward them explicitly through extraHeaders, instead of relying on Node.js writeHead() implicitly merging setHeader() calls. This prevents silent header loss if streamPageToResponse is refactored. - Support array-valued headers (e.g. multiple Set-Cookie) in streamPageToResponse by using res.setHeader() for arrays. - Add comments explaining the middleware header behavior when gSSP calls res.end() (dev includes them via the shared res object, prod merges them via the worker entry).