@@ -56,7 +56,7 @@ const {
56
56
const { kHeadersList } = require ( '../core/symbols' )
57
57
const EE = require ( 'events' )
58
58
const { Readable, pipeline } = require ( 'stream' )
59
- const { isErrored, isReadable, nodeMajor, nodeMinor } = require ( '../core/util' )
59
+ const { addAbortListener , isErrored, isReadable, nodeMajor, nodeMinor } = require ( '../core/util' )
60
60
const { dataURLProcessor, serializeAMimeType } = require ( './dataURL' )
61
61
const { TransformStream } = require ( 'stream/web' )
62
62
const { getGlobalDispatcher } = require ( '../global' )
@@ -174,22 +174,22 @@ async function fetch (input, init = {}) {
174
174
let controller = null
175
175
176
176
// 11. Add the following abort steps to requestObject’s signal:
177
- requestObject . signal . addEventListener (
178
- 'abort' ,
177
+ addAbortListener (
178
+ requestObject . signal ,
179
179
( ) => {
180
180
// 1. Set locallyAborted to true.
181
181
locallyAborted = true
182
182
183
- // 2. Abort the fetch() call with p, request, responseObject,
183
+ // 2. Assert: controller is non-null.
184
+ assert ( controller != null )
185
+
186
+ // 3. Abort controller with requestObject’s signal’s abort reason.
187
+ controller . abort ( requestObject . signal . reason )
188
+
189
+ // 4. Abort the fetch() call with p, request, responseObject,
184
190
// and requestObject’s signal’s abort reason.
185
191
abortFetch ( p , request , responseObject , requestObject . signal . reason )
186
-
187
- // 3. If controller is not null, then abort controller.
188
- if ( controller != null ) {
189
- controller . abort ( )
190
- }
191
- } ,
192
- { once : true }
192
+ }
193
193
)
194
194
195
195
// 12. Let handleFetchDone given response response be to finalize and
@@ -319,7 +319,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
319
319
// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
320
320
function markResourceTiming ( timingInfo , originalURL , initiatorType , globalThis , cacheState ) {
321
321
if ( nodeMajor > 18 || ( nodeMajor === 18 && nodeMinor >= 2 ) ) {
322
- performance . markResourceTiming ( timingInfo , originalURL , initiatorType , globalThis , cacheState )
322
+ performance . markResourceTiming ( timingInfo , originalURL . href , initiatorType , globalThis , cacheState )
323
323
}
324
324
}
325
325
@@ -1986,7 +1986,7 @@ async function httpNetworkFetch (
1986
1986
if ( key . toLowerCase ( ) === 'content-encoding' ) {
1987
1987
// https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1
1988
1988
// "All content-coding values are case-insensitive..."
1989
- codings = val . toLowerCase ( ) . split ( ',' ) . map ( ( x ) => x . trim ( ) )
1989
+ codings = val . toLowerCase ( ) . split ( ',' ) . map ( ( x ) => x . trim ( ) ) . reverse ( )
1990
1990
} else if ( key . toLowerCase ( ) === 'location' ) {
1991
1991
location = val
1992
1992
}
@@ -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' ) {
0 commit comments