@@ -235,7 +235,11 @@ export default async function fetch(url, options_) {
235
235
} ) ;
236
236
}
237
237
238
- let body = pump ( response_ , new PassThrough ( ) , reject ) ;
238
+ let body = pump ( response_ , new PassThrough ( ) , error => {
239
+ if ( error ) {
240
+ reject ( error ) ;
241
+ }
242
+ } ) ;
239
243
// see https://github.com/nodejs/node/pull/29376
240
244
/* c8 ignore next 3 */
241
245
if ( process . version < 'v12.10' ) {
@@ -281,7 +285,11 @@ export default async function fetch(url, options_) {
281
285
282
286
// For gzip
283
287
if ( codings === 'gzip' || codings === 'x-gzip' ) {
284
- body = pump ( body , zlib . createGunzip ( zlibOptions ) , reject ) ;
288
+ body = pump ( body , zlib . createGunzip ( zlibOptions ) , error => {
289
+ if ( error ) {
290
+ reject ( error ) ;
291
+ }
292
+ } ) ;
285
293
response = new Response ( body , responseOptions ) ;
286
294
resolve ( response ) ;
287
295
return ;
@@ -291,20 +299,48 @@ export default async function fetch(url, options_) {
291
299
if ( codings === 'deflate' || codings === 'x-deflate' ) {
292
300
// Handle the infamous raw deflate response from old servers
293
301
// a hack for old IIS and Apache servers
294
- const raw = pump ( response_ , new PassThrough ( ) , reject ) ;
302
+ const raw = pump ( response_ , new PassThrough ( ) , error => {
303
+ if ( error ) {
304
+ reject ( error ) ;
305
+ }
306
+ } ) ;
295
307
raw . once ( 'data' , chunk => {
296
308
// See http://stackoverflow.com/questions/37519828
297
- body = ( chunk [ 0 ] & 0x0F ) === 0x08 ? pump ( body , zlib . createInflate ( ) , reject ) : pump ( body , zlib . createInflateRaw ( ) , reject ) ;
309
+ if ( ( chunk [ 0 ] & 0x0F ) === 0x08 ) {
310
+ body = pump ( body , zlib . createInflate ( ) , error => {
311
+ if ( error ) {
312
+ reject ( error ) ;
313
+ }
314
+ } ) ;
315
+ } else {
316
+ body = pump ( body , zlib . createInflateRaw ( ) , error => {
317
+ if ( error ) {
318
+ reject ( error ) ;
319
+ }
320
+ } ) ;
321
+ }
298
322
299
323
response = new Response ( body , responseOptions ) ;
300
324
resolve ( response ) ;
301
325
} ) ;
326
+ raw . once ( 'end' , ( ) => {
327
+ // Some old IIS servers return zero-length OK deflate responses, so
328
+ // 'data' is never emitted. See https://github.com/node-fetch/node-fetch/pull/903
329
+ if ( ! response ) {
330
+ response = new Response ( body , responseOptions ) ;
331
+ resolve ( response ) ;
332
+ }
333
+ } ) ;
302
334
return ;
303
335
}
304
336
305
337
// For br
306
338
if ( codings === 'br' ) {
307
- body = pump ( body , zlib . createBrotliDecompress ( ) , reject ) ;
339
+ body = pump ( body , zlib . createBrotliDecompress ( ) , error => {
340
+ if ( error ) {
341
+ reject ( error ) ;
342
+ }
343
+ } ) ;
308
344
response = new Response ( body , responseOptions ) ;
309
345
resolve ( response ) ;
310
346
return ;
0 commit comments