Skip to content

Commit

Permalink
fix: removed unwanted copy of cookies logic
Browse files Browse the repository at this point in the history
  • Loading branch information
technikhil314 committed Mar 12, 2024
1 parent f6a685a commit 348c28e
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,38 +220,22 @@ async function createRedirectRenderResult(
if (
headResponse.headers.get('content-type') === RSC_CONTENT_TYPE_HEADER
) {
const redirectResponse = await fetch(fetchUrl, {
const response = await fetch(fetchUrl, {
method: 'GET',
headers: forwardedHeaders,
next: {
// @ts-ignore
internal: 1,
},
})
//copy cookies from the redirect response to respose we're sending before copying other headers
//this is needed only in case of custom server created by developer
//cause nextjs app dir does not allow to set cookies from components
const redirectResponseCookies = new ResponseCookies(
redirectResponse.headers
)
const responseCookies = new ResponseCookies(
fromNodeOutgoingHttpHeaders(res.getHeaders())
)
redirectResponseCookies.getAll().forEach((cookie) => {
if (typeof cookie.value === 'undefined') {
responseCookies.delete(cookie.name)
} else {
responseCookies.set(cookie)
}
})
// copy the headers from the redirect response to the response we're sending
for (const [key, value] of redirectResponse.headers) {
for (const [key, value] of response.headers) {
if (!actionsForbiddenHeaders.includes(key)) {
res.setHeader(key, value)
}
}

return new FlightRenderResult(redirectResponse.body!)
return new FlightRenderResult(response.body!)
}
} catch (err) {
// we couldn't stream the redirect response, so we'll just do a normal redirect
Expand Down

0 comments on commit 348c28e

Please sign in to comment.