@@ -37,7 +37,10 @@ const {
37
37
isErrorLike,
38
38
fullyReadBody,
39
39
readableStreamClose,
40
- isomorphicEncode
40
+ isomorphicEncode,
41
+ urlIsLocal,
42
+ urlIsHttpHttpsScheme,
43
+ urlHasHttpsScheme
41
44
} = require ( './util' )
42
45
const { kState, kHeaders, kGuard, kRealm, kHeadersCaseInsensitive } = require ( './symbols' )
43
46
const assert = require ( 'assert' )
@@ -272,7 +275,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
272
275
let cacheState = response . cacheState
273
276
274
277
// 6. If originalURL’s scheme is not an HTTP(S) scheme, then return.
275
- if ( ! / ^ h t t p s ? : / . test ( originalURL . protocol ) ) {
278
+ if ( ! urlIsHttpHttpsScheme ( originalURL ) ) {
276
279
return
277
280
}
278
281
@@ -530,10 +533,7 @@ async function mainFetch (fetchParams, recursive = false) {
530
533
531
534
// 3. If request’s local-URLs-only flag is set and request’s current URL is
532
535
// not local, then set response to a network error.
533
- if (
534
- request . localURLsOnly &&
535
- ! / ^ ( a b o u t | b l o b | d a t a ) : / . test ( requestCurrentURL ( request ) . protocol )
536
- ) {
536
+ if ( request . localURLsOnly && ! urlIsLocal ( requestCurrentURL ( request ) ) ) {
537
537
response = makeNetworkError ( 'local URLs only' )
538
538
}
539
539
@@ -623,7 +623,7 @@ async function mainFetch (fetchParams, recursive = false) {
623
623
}
624
624
625
625
// request’s current URL’s scheme is not an HTTP(S) scheme
626
- if ( ! / ^ h t t p s ? : / . test ( requestCurrentURL ( request ) . protocol ) ) {
626
+ if ( ! urlIsHttpHttpsScheme ( requestCurrentURL ( request ) ) ) {
627
627
// Return a network error.
628
628
return makeNetworkError ( 'URL scheme must be a HTTP(S) scheme' )
629
629
}
@@ -1130,7 +1130,7 @@ async function httpRedirectFetch (fetchParams, response) {
1130
1130
1131
1131
// 6. If locationURL’s scheme is not an HTTP(S) scheme, then return a network
1132
1132
// error.
1133
- if ( ! / ^ h t t p s ? : / . test ( locationURL . protocol ) ) {
1133
+ if ( ! urlIsHttpHttpsScheme ( locationURL ) ) {
1134
1134
return makeNetworkError ( 'URL scheme must be a HTTP(S) scheme' )
1135
1135
}
1136
1136
@@ -1399,7 +1399,7 @@ async function httpNetworkOrCacheFetch (
1399
1399
// header if httpRequest’s header list contains that header’s name.
1400
1400
// TODO: https://github.com/whatwg/fetch/issues/1285#issuecomment-896560129
1401
1401
if ( ! httpRequest . headersList . contains ( 'accept-encoding' ) ) {
1402
- if ( / ^ h t t p s : / . test ( requestCurrentURL ( httpRequest ) . protocol ) ) {
1402
+ if ( urlHasHttpsScheme ( requestCurrentURL ( httpRequest ) ) ) {
1403
1403
httpRequest . headersList . append ( 'accept-encoding' , 'br, gzip, deflate' )
1404
1404
} else {
1405
1405
httpRequest . headersList . append ( 'accept-encoding' , 'gzip, deflate' )
0 commit comments