Skip to content

Commit

Permalink
Stash extra headers on the metadata of the renderresult instead
Browse files Browse the repository at this point in the history
This ensures that we only track the static headers we want to track.
  • Loading branch information
sebmarkbage committed Nov 8, 2023
1 parent 7752890 commit f501fce
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/export/routes/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function exportAppPage(
)
}

const headers = toNodeOutgoingHttpHeaders(res.headers)
const headers = { ...metadata.extraHeaders }

if (fetchTags) {
headers[NEXT_CACHE_TAGS_HEADER] = fetchTags
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ async function renderToHTMLOrFlightImpl(
// Copy headers created by React into the response object.
headers.forEach((value: string, key: string) => {
res.appendHeader(key, value)
if (!extraRenderResultMeta.extraHeaders) {
extraRenderResultMeta.extraHeaders = {}
}
extraRenderResultMeta.extraHeaders[key] = value
})
}

Expand Down
3 changes: 1 addition & 2 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2374,8 +2374,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Add any fetch tags that were on the page to the response headers.
const cacheTags = metadata.fetchTags

// Copy the headers from the response.
headers = { ...res.getHeaders() }
headers = { ...metadata.extraHeaders }

if (cacheTags) {
headers[NEXT_CACHE_TAGS_HEADER] = cacheTags
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/render-result.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerResponse } from 'http'
import type { OutgoingHttpHeaders, ServerResponse } from 'http'
import type { StaticGenerationStore } from '../client/components/static-generation-async-storage.external'
import type { Revalidate } from './lib/revalidate'

Expand All @@ -23,6 +23,7 @@ export type RenderResultMetadata = {
isRedirect?: boolean
fetchMetrics?: StaticGenerationStore['fetchMetrics']
fetchTags?: string
extraHeaders?: OutgoingHttpHeaders
waitUntil?: Promise<any>
postponed?: string
}
Expand Down

0 comments on commit f501fce

Please sign in to comment.