@@ -181,6 +181,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
181181 : [ ...initialCookies , ...this . _cookies ] ;
182182 }
183183 this . fixHeaders ( this . headers ) ;
184+ this . fixHeadersForError ( ) ;
184185
185186 // We need to fix the set-cookie header here
186187 this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
@@ -274,6 +275,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
274275 getFixedHeaders ( ) : OutgoingHttpHeaders {
275276 // Do we want to apply this on writeHead?
276277 this . fixHeaders ( this . headers ) ;
278+ this . fixHeadersForError ( ) ;
277279 // This way we ensure that the cookies are correct
278280 this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
279281 return this . headers ;
@@ -369,4 +371,16 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
369371 //TODO: test to see if we need to call end here
370372 return this ;
371373 }
374+
375+ // For some reason, next returns the 500 error page with some cache-control headers
376+ // We need to fix that
377+ private fixHeadersForError ( ) {
378+ // We only check for 404 and 500 errors
379+ // The rest should be errors that are handled by the user and they should set the cache headers themselves
380+ if ( this . statusCode === 404 || this . statusCode === 500 ) {
381+ this . setHeader ( "Cache-Control" , "no-cache, no-store, must-revalidate" ) ;
382+ this . setHeader ( "Pragma" , "no-cache" ) ;
383+ this . setHeader ( "Expires" , "0" ) ;
384+ }
385+ }
372386}
0 commit comments