@@ -5,6 +5,7 @@ const { ono } = require("@jsdevtools/ono");
55const { AbortController } = require ( "node-abort-controller" ) ;
66const url = require ( "../util/url" ) ;
77const { ResolverError } = require ( "../util/errors" ) ;
8+ const { isBrowser } = require ( "../util/environment" ) ;
89
910module . exports = {
1011 /**
@@ -73,12 +74,7 @@ module.exports = {
7374 * @returns {Promise<Uint8Array | string> }
7475 */
7576 read ( file ) {
76- let u = url . parse ( file . url ) ;
77-
78- if ( process . browser && ! u . protocol ) {
79- // Use the protocol of the current page
80- u . protocol = url . parse ( location . href ) . protocol ;
81- }
77+ let u = process . browser ? new URL ( file . url , location . origin ) : new URL ( file . url ) ;
8278
8379 return download ( u , this , [ ] ) ;
8480 } ,
@@ -87,7 +83,7 @@ module.exports = {
8783/**
8884 * Downloads the given file.
8985 *
90- * @param {Url |string } u - The url to download (can be a parsed {@link Url } object)
86+ * @param {URL |string } u - The url to download (can be a parsed {@link URL } object)
9187 * @param {object } httpOptions - The `options.resolve.http` object
9288 * @param {string[] } redirects - The redirect URLs that have already been followed
9389 *
@@ -106,7 +102,7 @@ async function download (u, httpOptions, redirects) {
106102 headers . set ( "Authorization" , "Basic " + btoa ( u . auth ) ) ;
107103 }
108104
109- u = url . parse ( url . format ( Object . assign ( u , { auth : "" } ) ) ) ;
105+ u . auth = "" ;
110106
111107 const controller = new AbortController ( ) ;
112108
@@ -157,7 +153,7 @@ async function download (u, httpOptions, redirects) {
157153 ) ;
158154 }
159155
160- let redirectTo = url . resolve ( u , location ) ;
156+ let redirectTo = url . resolve ( u . href , location ) ;
161157 return await download ( redirectTo , httpOptions , redirects ) ;
162158 }
163159
0 commit comments