File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -1958,8 +1958,12 @@ async function httpNetworkFetch (
1958
1958
1959
1959
const decoders = [ ]
1960
1960
1961
+ const willFollow = request . redirect === 'follow' &&
1962
+ location &&
1963
+ redirectStatus . includes ( status )
1964
+
1961
1965
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
1962
- if ( request . method !== 'HEAD' && request . method !== 'CONNECT' && ! nullBodyStatus . includes ( status ) && ! ( request . redirect === 'follow' && location ) ) {
1966
+ if ( request . method !== 'HEAD' && request . method !== 'CONNECT' && ! nullBodyStatus . includes ( status ) && ! willFollow ) {
1963
1967
for ( const coding of codings ) {
1964
1968
if ( / ( x - ) ? g z i p / . test ( coding ) ) {
1965
1969
decoders . push ( zlib . createGunzip ( ) )
Original file line number Diff line number Diff line change @@ -533,6 +533,25 @@ test('do not decode redirect body', (t) => {
533
533
} )
534
534
} )
535
535
536
+ test ( 'decode non-redirect body with location header' , ( t ) => {
537
+ t . plan ( 2 )
538
+
539
+ const obj = { asd : true }
540
+ const server = createServer ( ( req , res ) => {
541
+ t . pass ( 'response' )
542
+ res . statusCode = 201
543
+ res . setHeader ( 'location' , '/resource/' )
544
+ res . setHeader ( 'content-encoding' , 'gzip' )
545
+ res . end ( gzipSync ( JSON . stringify ( obj ) ) )
546
+ } )
547
+ t . teardown ( server . close . bind ( server ) )
548
+
549
+ server . listen ( 0 , async ( ) => {
550
+ const body = await fetch ( `http://localhost:${ server . address ( ) . port } /resource` )
551
+ t . strictSame ( JSON . stringify ( obj ) , await body . text ( ) )
552
+ } )
553
+ } )
554
+
536
555
test ( 'Receiving non-Latin1 headers' , async ( t ) => {
537
556
const ContentDisposition = [
538
557
'inline; filename=rock&roll.png' ,
You can’t perform that action at this time.
0 commit comments