@@ -8,23 +8,13 @@ import type { Socket } from "node:net";
88import type { TransformCallback , Writable } from "node:stream" ;
99import { Transform } from "node:stream" ;
1010
11+ import type { StreamCreator } from "types/open-next" ;
1112import { debug } from "../adapters/logger" ;
1213import { parseCookies , parseHeaders } from "./util" ;
1314
1415const SET_COOKIE_HEADER = "set-cookie" ;
1516const CANNOT_BE_USED = "This cannot be used in OpenNext" ;
1617
17- export interface StreamCreator {
18- writeHeaders ( prelude : {
19- statusCode : number ;
20- cookies : string [ ] ;
21- headers : Record < string , string > ;
22- } ) : Writable ;
23- // Just to fix an issue with aws lambda streaming with empty body
24- onWrite ?: ( ) => void ;
25- onFinish : ( length : number ) => void ;
26- }
27-
2818// We only need to implement the methods that are used by next.js
2919export class OpenNextNodeResponse extends Transform implements ServerResponse {
3020 statusCode ! : number ;
@@ -92,9 +82,9 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
9282 }
9383
9484 get finished ( ) {
95- return Boolean (
96- this . writableFinished && this . responseStream ?. writableFinished ,
97- ) ;
85+ return this . responseStream
86+ ? this . responseStream ?. writableFinished
87+ : this . writableFinished ;
9888 }
9989
10090 setHeader ( name : string , value : string | string [ ] ) : this {
@@ -303,7 +293,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
303293 ?. getStore ( )
304294 ?. pendingPromiseRunner . add ( this . onEnd ( this . headers ) ) ;
305295 const bodyLength = this . getBody ( ) . length ;
306- this . streamCreator ?. onFinish ( bodyLength ) ;
296+ this . streamCreator ?. onFinish ?. ( bodyLength ) ;
307297
308298 //This is only here because of aws broken streaming implementation.
309299 //Hopefully one day they will be able to give us a working streaming implementation in lambda for everyone
0 commit comments