Skip to content

Commit

Permalink
revert changes for x-middleware-set-cookie and mergeMiddlewareCookies…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
abhi12299 committed Sep 30, 2024
1 parent cd89568 commit 2d66bc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
18 changes: 7 additions & 11 deletions packages/next/src/server/async-storage/with-request-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { splitCookiesString } from '../web/utils'
import { AfterContext } from '../after/after-context'
import type { RequestLifecycleOpts } from '../base-server'
import type { ServerComponentsHmrCache } from '../response-cache'
import { getRequestMeta, type NextIncomingMessage } from '../request-meta'

function getHeaders(headers: Headers | IncomingHttpHeaders): ReadonlyHeaders {
const cleaned = HeadersAdapter.from(headers)
Expand Down Expand Up @@ -89,20 +88,17 @@ type RequestResponsePair =
* it's able to read the newly set cookies.
*/
function mergeMiddlewareCookies(
req: RequestContext['req'] | NextIncomingMessage,
req: RequestContext['req'],
existingCookies: RequestCookies | ResponseCookies
) {
const middlewareCookies = getRequestMeta(
req as NextIncomingMessage,
'middlewareCookie'
)
if (middlewareCookies && middlewareCookies.length > 0) {
const cookies = middlewareCookies.flatMap((maybeCompoundCookie) =>
splitCookiesString(maybeCompoundCookie)
)
if (
'x-middleware-set-cookie' in req.headers &&
typeof req.headers['x-middleware-set-cookie'] === 'string'
) {
const setCookieValue = req.headers['x-middleware-set-cookie']
const responseHeaders = new Headers()

for (const cookie of cookies) {
for (const cookie of splitCookiesString(setCookieValue)) {
responseHeaders.append('set-cookie', cookie)
}

Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/web/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const FORBIDDEN_HEADERS = [
'content-length',
'content-encoding',
'transfer-encoding',
'x-middleware-set-cookie',
]

interface RunnerFnParams {
Expand Down

0 comments on commit 2d66bc8

Please sign in to comment.