@@ -41,6 +41,7 @@ export class StreamingServerResponse extends http.ServerResponse {
41
41
}
42
42
try {
43
43
this . fixHeaders ( this [ HEADERS ] ) ;
44
+ this . _wroteHeader = true ;
44
45
this . responseStream = awslambda . HttpResponseStream . from (
45
46
this . responseStream ,
46
47
{
@@ -49,7 +50,6 @@ export class StreamingServerResponse extends http.ServerResponse {
49
50
} ,
50
51
) ;
51
52
52
- this . _wroteHeader = true ;
53
53
debug ( "writeHead" , this [ HEADERS ] ) ;
54
54
} catch ( e ) {
55
55
this . responseStream . end ( ) ;
@@ -76,12 +76,15 @@ export class StreamingServerResponse extends http.ServerResponse {
76
76
this . internalWrite ( chunk ) ;
77
77
}
78
78
79
+ if ( ! this . _hasWritten ) {
80
+ // We need to send data here, otherwise the stream will not end at all
81
+ this . internalWrite ( new Uint8Array ( 8 ) ) ;
82
+ }
83
+
79
84
setImmediate ( ( ) => {
80
- if ( ! this . _hasWritten ) {
81
- // We need to send data here, otherwise the stream will not end at all
82
- this . internalWrite ( new Uint8Array ( 8 ) ) ;
83
- }
84
- this . responseStream . end ( ) ;
85
+ this . responseStream . end ( ( ) => {
86
+ debug ( "stream end" , chunk ) ;
87
+ } ) ;
85
88
} ) ;
86
89
debug ( "stream end" , chunk ) ;
87
90
return this ;
@@ -114,15 +117,17 @@ export class StreamingServerResponse extends http.ServerResponse {
114
117
_writableState : { } ,
115
118
writable : true ,
116
119
// @ts -ignore
117
- on : Function . prototype ,
120
+ on : this . responseStream . on . bind ( this . responseStream ) ,
118
121
// @ts -ignore
119
- removeListener : Function . prototype ,
122
+ removeListener : this . responseStream . removeListener . bind (
123
+ this . responseStream ,
124
+ ) ,
120
125
// @ts -ignore
121
- destroy : Function . prototype ,
126
+ destroy : this . responseStream . destroy . bind ( this . responseStream ) ,
122
127
// @ts -ignore
123
- cork : Function . prototype ,
128
+ cork : this . responseStream . cork . bind ( this . responseStream ) ,
124
129
// @ts -ignore
125
- uncork : Function . prototype ,
130
+ uncork : this . responseStream . uncork . bind ( this . responseStream ) ,
126
131
// @ts -ignore
127
132
write : ( data , encoding , cb ) => {
128
133
if ( typeof encoding === "function" ) {
@@ -141,8 +146,8 @@ export class StreamingServerResponse extends http.ServerResponse {
141
146
142
147
this . responseStream . on ( "error" , ( err ) => {
143
148
this . emit ( "error" , err ) ;
144
- this . responseStream . end ( ) ;
145
149
error ( "error" , err ) ;
150
+ this . responseStream . end ( ) ;
146
151
} ) ;
147
152
}
148
153
}
0 commit comments