File tree 2 files changed +14
-9
lines changed
2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -2007,7 +2007,14 @@ async function httpNetworkFetch (
2007
2007
for ( const coding of codings ) {
2008
2008
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
2009
2009
if ( coding === 'x-gzip' || coding === 'gzip' ) {
2010
- decoders . push ( zlib . createGunzip ( ) )
2010
+ decoders . push ( zlib . createGunzip ( {
2011
+ // Be less strict when decoding compressed responses, since sometimes
2012
+ // servers send slightly invalid responses that are still accepted
2013
+ // by common browsers.
2014
+ // Always using Z_SYNC_FLUSH is what cURL does.
2015
+ flush : zlib . constants . Z_SYNC_FLUSH ,
2016
+ finishFlush : zlib . constants . Z_SYNC_FLUSH
2017
+ } ) )
2011
2018
} else if ( coding === 'deflate' ) {
2012
2019
decoders . push ( zlib . createInflate ( ) )
2013
2020
} else if ( coding === 'br' ) {
Original file line number Diff line number Diff line change @@ -640,15 +640,13 @@ describe('node-fetch', () => {
640
640
} )
641
641
} )
642
642
643
- xit ( 'should decompress slightly invalid gzip response' , ( ) => {
643
+ it ( 'should decompress slightly invalid gzip response' , async ( ) => {
644
644
const url = `${ base } gzip-truncated`
645
- return fetch ( url ) . then ( res => {
646
- expect ( res . headers . get ( 'content-type' ) ) . to . equal ( 'text/plain' )
647
- return res . text ( ) . then ( result => {
648
- expect ( result ) . to . be . a ( 'string' )
649
- expect ( result ) . to . equal ( 'hello world' )
650
- } )
651
- } )
645
+ const res = await fetch ( url )
646
+ expect ( res . headers . get ( 'content-type' ) ) . to . equal ( 'text/plain' )
647
+ const result = await res . text ( )
648
+ expect ( result ) . to . be . a ( 'string' )
649
+ expect ( result ) . to . equal ( 'hello world' )
652
650
} )
653
651
654
652
it ( 'should decompress deflate response' , ( ) => {
You can’t perform that action at this time.
0 commit comments