@@ -8,23 +8,13 @@ import type { Socket } from "node:net";
8
8
import type { TransformCallback , Writable } from "node:stream" ;
9
9
import { Transform } from "node:stream" ;
10
10
11
+ import type { StreamCreator } from "types/open-next" ;
11
12
import { debug } from "../adapters/logger" ;
12
13
import { parseCookies , parseHeaders } from "./util" ;
13
14
14
15
const SET_COOKIE_HEADER = "set-cookie" ;
15
16
const CANNOT_BE_USED = "This cannot be used in OpenNext" ;
16
17
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
-
28
18
// We only need to implement the methods that are used by next.js
29
19
export class OpenNextNodeResponse extends Transform implements ServerResponse {
30
20
statusCode ! : number ;
@@ -92,9 +82,9 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
92
82
}
93
83
94
84
get finished ( ) {
95
- return Boolean (
96
- this . writableFinished && this . responseStream ?. writableFinished ,
97
- ) ;
85
+ return this . responseStream
86
+ ? this . responseStream ?. writableFinished
87
+ : this . writableFinished ;
98
88
}
99
89
100
90
setHeader ( name : string , value : string | string [ ] ) : this {
@@ -303,7 +293,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
303
293
?. getStore ( )
304
294
?. pendingPromiseRunner . add ( this . onEnd ( this . headers ) ) ;
305
295
const bodyLength = this . getBody ( ) . length ;
306
- this . streamCreator ?. onFinish ( bodyLength ) ;
296
+ this . streamCreator ?. onFinish ?. ( bodyLength ) ;
307
297
308
298
//This is only here because of aws broken streaming implementation.
309
299
//Hopefully one day they will be able to give us a working streaming implementation in lambda for everyone
0 commit comments