@@ -138,15 +138,16 @@ function isRedirect(statusCode) {
138
138
* @param {URL } parsed
139
139
* @returns {Promise<CacheEntry> | CacheEntry }
140
140
*/
141
- function fetchWithRedirects ( parsed ) {
141
+ function fetchWithRedirects ( parsed , context ) {
142
142
const existing = cacheForGET . get ( parsed . href ) ;
143
143
if ( existing ) {
144
144
return existing ;
145
145
}
146
146
const handler = parsed . protocol === 'http:' ? HTTPGet : HTTPSGet ;
147
147
const result = ( async ( ) => {
148
+ const extension = context . importAssertions ?. type ;
148
149
const req = handler ( parsed , {
149
- headers : { Accept : ' */*' } ,
150
+ headers : { Accept : extension === 'json' ? 'application/json, */*;' : '*/*; ' } ,
150
151
} ) ;
151
152
// Note that `once` is used here to handle `error` and that it hits the
152
153
// `finally` on network error/timeout.
@@ -162,7 +163,7 @@ function fetchWithRedirects(parsed) {
162
163
'cannot redirect to non-network location' ,
163
164
) ;
164
165
}
165
- const entry = await fetchWithRedirects ( location ) ;
166
+ const entry = await fetchWithRedirects ( location , context ) ;
166
167
cacheForGET . set ( parsed . href , entry ) ;
167
168
return entry ;
168
169
}
@@ -262,7 +263,8 @@ async function isLocalAddress(hostname) {
262
263
* @param {ESModuleContext } context
263
264
* @returns {ReturnType<typeof fetchWithRedirects> }
264
265
*/
265
- function fetchModule ( parsed , { parentURL } ) {
266
+ function fetchModule ( parsed , context ) {
267
+ const { parentURL } = context ;
266
268
const { href } = parsed ;
267
269
const existing = cacheForGET . get ( href ) ;
268
270
if ( existing ) {
@@ -277,10 +279,10 @@ function fetchModule(parsed, { parentURL }) {
277
279
'http can only be used to load local resources (use https instead).' ,
278
280
) ;
279
281
}
280
- return fetchWithRedirects ( parsed ) ;
282
+ return fetchWithRedirects ( parsed , context ) ;
281
283
} ) ;
282
284
}
283
- return fetchWithRedirects ( parsed ) ;
285
+ return fetchWithRedirects ( parsed , context ) ;
284
286
}
285
287
286
288
module . exports = {
0 commit comments