Skip to content

Commit

Permalink
fix: respect res header immutability (#10554)
Browse files Browse the repository at this point in the history
Properly respect and merge res headers.
  • Loading branch information
denolfe authored Jan 13, 2025
1 parent 9278eec commit 5cfb1da
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/payload/src/utilities/handleEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { PayloadRequest } from '../types/index.js'

import { createPayloadRequest } from './createPayloadRequest.js'
import { headersWithCors } from './headersWithCors.js'
import { mergeHeaders } from './mergeHeaders.js'
import { routeError } from './routeError.js'

const notFoundResponse = (req: PayloadRequest) => {
Expand Down Expand Up @@ -215,14 +216,11 @@ export const handleEndpoints = async ({
}

const response = await handler(req)

if (req.responseHeaders) {
for (const [key, value] of req.responseHeaders) {
response.headers.append(key, value)
}
}

return response
return new Response(response.body, {
headers: mergeHeaders(req.responseHeaders ?? new Headers(), response.headers),
status: response.status,
statusText: response.statusText,
})
} catch (err) {
return routeError({
collection,
Expand Down

0 comments on commit 5cfb1da

Please sign in to comment.