@@ -1190,38 +1190,45 @@ describe('transmission', () => {
1190
1190
await log ;
1191
1191
} ) ;
1192
1192
1193
- it ( 'stops processing the stream when the request closes' , async ( ) => {
1193
+ it ( 'stops processing the stream when the connection closes' , async ( ) => {
1194
+
1195
+ let stream ;
1194
1196
1195
1197
const ErrStream = class extends Stream . Readable {
1196
1198
1197
1199
constructor ( request ) {
1198
1200
1199
1201
super ( ) ;
1200
1202
this . request = request ;
1203
+ this . reads = 0 ;
1201
1204
}
1202
1205
1203
1206
_read ( size ) {
1204
1207
1205
- if ( this . isDone ) {
1206
- return ;
1208
+ if ( this . reads === 0 ) {
1209
+ this . push ( 'here is the response' ) ;
1210
+ this . request . raw . res . destroy ( ) ;
1207
1211
}
1212
+ else {
1213
+ // "Inifitely" push more content
1208
1214
1209
- this . isDone = true ;
1210
- this . push ( 'here is the response' ) ;
1211
- process . nextTick ( ( ) => {
1212
-
1213
- this . request . raw . req . emit ( 'close' ) ;
1214
1215
process . nextTick ( ( ) => {
1215
1216
1216
- this . push ( null ) ;
1217
+ this . push ( '.' ) ;
1217
1218
} ) ;
1218
- } ) ;
1219
+ }
1220
+
1221
+ ++ this . reads ;
1219
1222
}
1220
1223
} ;
1221
1224
1222
1225
const server = Hapi . server ( ) ;
1223
1226
const log = server . events . once ( 'response' ) ;
1224
- server . route ( { method : 'GET' , path : '/stream' , handler : ( request , h ) => h . response ( new ErrStream ( request ) ) . bytes ( 0 ) } ) ;
1227
+ server . route ( { method : 'GET' , path : '/stream' , handler : ( request , h ) => {
1228
+
1229
+ stream = new ErrStream ( request ) ;
1230
+ return h . response ( stream ) . bytes ( 0 ) ;
1231
+ } } ) ;
1225
1232
1226
1233
const res = await server . inject ( { url : '/stream' , headers : { 'Accept-Encoding' : 'gzip' } } ) ;
1227
1234
expect ( res . statusCode ) . to . equal ( 499 ) ;
@@ -1234,6 +1241,8 @@ describe('transmission', () => {
1234
1241
expect ( request . response . statusCode ) . to . equal ( 499 ) ;
1235
1242
expect ( request . info . completed ) . to . be . above ( 0 ) ;
1236
1243
expect ( request . info . responded ) . to . equal ( 0 ) ;
1244
+
1245
+ expect ( stream . reads ) . to . equal ( 2 ) ;
1237
1246
} ) ;
1238
1247
1239
1248
it ( 'does not truncate the response when stream finishes before response is done' , async ( ) => {
0 commit comments