@@ -83,7 +83,7 @@ import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
83
83
import { loadComponents } from './load-components'
84
84
import isError , { getProperError } from '../lib/is-error'
85
85
import { FontManifest } from './font-utils'
86
- import { toNodeHeaders } from './web/utils'
86
+ import { splitCookiesString , toNodeHeaders } from './web/utils'
87
87
import { relativizeURL } from '../shared/lib/router/utils/relativize-url'
88
88
import { prepareDestination } from '../shared/lib/router/utils/prepare-destination'
89
89
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
@@ -1051,9 +1051,17 @@ export default class NextNodeServer extends BaseServer {
1051
1051
name : '_next/data catchall' ,
1052
1052
check : true ,
1053
1053
fn : async ( req , res , params , _parsedUrl ) => {
1054
+ const isNextDataNormalizing = getRequestMeta (
1055
+ req ,
1056
+ '_nextDataNormalizing'
1057
+ )
1058
+
1054
1059
// Make sure to 404 for /_next/data/ itself and
1055
1060
// we also want to 404 if the buildId isn't correct
1056
1061
if ( ! params . path || params . path [ 0 ] !== this . buildId ) {
1062
+ if ( isNextDataNormalizing ) {
1063
+ return { finished : false }
1064
+ }
1057
1065
await this . render404 ( req , res , _parsedUrl )
1058
1066
return {
1059
1067
finished : true ,
@@ -1797,6 +1805,14 @@ export default class NextNodeServer extends BaseServer {
1797
1805
} else {
1798
1806
for ( let [ key , value ] of allHeaders ) {
1799
1807
result . response . headers . set ( key , value )
1808
+
1809
+ if ( key . toLowerCase ( ) === 'set-cookie' ) {
1810
+ addRequestMeta (
1811
+ params . request ,
1812
+ '_nextMiddlewareCookie' ,
1813
+ splitCookiesString ( value )
1814
+ )
1815
+ }
1800
1816
}
1801
1817
}
1802
1818
@@ -2105,8 +2121,13 @@ export default class NextNodeServer extends BaseServer {
2105
2121
params . res . statusCode = result . response . status
2106
2122
params . res . statusMessage = result . response . statusText
2107
2123
2108
- result . response . headers . forEach ( ( value , key ) => {
2109
- params . res . appendHeader ( key , value )
2124
+ result . response . headers . forEach ( ( value : string , key ) => {
2125
+ // the append handling is special cased for `set-cookie`
2126
+ if ( key . toLowerCase ( ) === 'set-cookie' ) {
2127
+ params . res . setHeader ( key , value )
2128
+ } else {
2129
+ params . res . appendHeader ( key , value )
2130
+ }
2110
2131
} )
2111
2132
2112
2133
if ( result . response . body ) {
0 commit comments