@@ -7,10 +7,10 @@ import type {
77 InternalResult ,
88 ResolvedRoute ,
99 RoutingResult ,
10- StreamCreator ,
1110} from "types/open-next" ;
1211import { runWithOpenNextRequestContext } from "utils/promise" ;
1312
13+ import type { OpenNextHandlerOptions } from "types/overrides" ;
1414import { debug , error , warn } from "../adapters/logger" ;
1515import { patchAsyncStorage } from "./patchAsyncStorage" ;
1616import { convertRes , createServerResponse } from "./routing/util" ;
@@ -29,12 +29,15 @@ patchAsyncStorage();
2929
3030export async function openNextHandler (
3131 internalEvent : InternalEvent ,
32- responseStreaming ?: StreamCreator ,
32+ options ?: OpenNextHandlerOptions ,
3333) : Promise < InternalResult > {
3434 const initialHeaders = internalEvent . headers ;
3535 // We run everything in the async local storage context so that it is available in the middleware as well as in NextServer
3636 return runWithOpenNextRequestContext (
37- { isISRRevalidation : initialHeaders [ "x-isr" ] === "1" } ,
37+ {
38+ isISRRevalidation : initialHeaders [ "x-isr" ] === "1" ,
39+ waitUntil : options ?. waitUntil ,
40+ } ,
3841 async ( ) => {
3942 if ( initialHeaders [ "x-forwarded-host" ] ) {
4043 initialHeaders . host = initialHeaders [ "x-forwarded-host" ] ;
@@ -116,7 +119,7 @@ export async function openNextHandler(
116119
117120 if ( "type" in routingResult ) {
118121 // response is used only in the streaming case
119- if ( responseStreaming ) {
122+ if ( options ?. streamCreator ) {
120123 const response = createServerResponse (
121124 {
122125 internalEvent,
@@ -127,7 +130,7 @@ export async function openNextHandler(
127130 initialPath : internalEvent . rawPath ,
128131 } ,
129132 headers ,
130- responseStreaming ,
133+ options . streamCreator ,
131134 ) ;
132135 response . statusCode = routingResult . statusCode ;
133136 response . flushHeaders ( ) ;
@@ -171,7 +174,7 @@ export async function openNextHandler(
171174 const res = createServerResponse (
172175 routingResult ,
173176 overwrittenResponseHeaders ,
174- responseStreaming ,
177+ options ?. streamCreator ,
175178 ) ;
176179
177180 await processRequest ( req , res , preprocessedEvent ) ;
0 commit comments