@@ -8,6 +8,7 @@ import type {
88 ResolvedRoute ,
99 RoutingResult ,
1010 StreamCreator ,
11+ WaitUntil ,
1112} from "types/open-next" ;
1213import { runWithOpenNextRequestContext } from "utils/promise" ;
1314
@@ -29,12 +30,18 @@ patchAsyncStorage();
2930
3031export async function openNextHandler (
3132 internalEvent : InternalEvent ,
32- responseStreaming ?: StreamCreator ,
33+ options ?: {
34+ streamCreator ?: StreamCreator ;
35+ waitUntil ?: WaitUntil ;
36+ } ,
3337) : Promise < InternalResult > {
3438 const initialHeaders = internalEvent . headers ;
3539 // We run everything in the async local storage context so that it is available in the middleware as well as in NextServer
3640 return runWithOpenNextRequestContext (
37- { isISRRevalidation : initialHeaders [ "x-isr" ] === "1" } ,
41+ {
42+ isISRRevalidation : initialHeaders [ "x-isr" ] === "1" ,
43+ waitUntil : options ?. waitUntil ,
44+ } ,
3845 async ( ) => {
3946 if ( initialHeaders [ "x-forwarded-host" ] ) {
4047 initialHeaders . host = initialHeaders [ "x-forwarded-host" ] ;
@@ -116,7 +123,7 @@ export async function openNextHandler(
116123
117124 if ( "type" in routingResult ) {
118125 // response is used only in the streaming case
119- if ( responseStreaming ) {
126+ if ( options ?. streamCreator ) {
120127 const response = createServerResponse (
121128 {
122129 internalEvent,
@@ -127,7 +134,7 @@ export async function openNextHandler(
127134 initialPath : internalEvent . rawPath ,
128135 } ,
129136 headers ,
130- responseStreaming ,
137+ options . streamCreator ,
131138 ) ;
132139 response . statusCode = routingResult . statusCode ;
133140 response . flushHeaders ( ) ;
@@ -171,7 +178,7 @@ export async function openNextHandler(
171178 const res = createServerResponse (
172179 routingResult ,
173180 overwrittenResponseHeaders ,
174- responseStreaming ,
181+ options ?. streamCreator ,
175182 ) ;
176183
177184 await processRequest ( req , res , preprocessedEvent ) ;
0 commit comments