MCPcopy Create free account
hub / github.com/nodejs/node / stripURLForReferrer

Function stripURLForReferrer

deps/undici/src/lib/web/fetch/util.js:524–556  ·  view source on GitHub ↗

* Certain portions of URLs must not be included when sending a URL as the * value of a `Referer` header: a URLs fragment, username, and password * components must be stripped from the URL before it’s sent out. This * algorithm accepts a origin-only flag, which defaults to false. If set to * true

(url, originOnly = false)

Source from the content-addressed store, hash-verified

522 * @param {boolean} [originOnly=false]
523 */
524function stripURLForReferrer (url, originOnly = false) {
525 // 1. Assert: url is a URL.
526 assert(webidl.is.URL(url))
527
528 // Note: Create a new URL instance to avoid mutating the original URL.
529 url = new URL(url)
530
531 // 2. If url’s scheme is a local scheme, then return no referrer.
532 if (urlIsLocal(url)) {
533 return 'no-referrer'
534 }
535
536 // 3. Set url’s username to the empty string.
537 url.username = ''
538
539 // 4. Set url’s password to the empty string.
540 url.password = ''
541
542 // 5. Set url’s fragment to null.
543 url.hash = ''
544
545 // 6. If the origin-only flag is true, then:
546 if (originOnly === true) {
547 // 1. Set url’s path to « the empty string ».
548 url.pathname = ''
549
550 // 2. Set url’s query to null.
551 url.search = ''
552 }
553
554 // 7. Return url.
555 return url
556}
557
558const isPotentialleTrustworthyIPv4 = RegExp.prototype.test
559 .bind(/^127\.(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){2}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)$/)

Callers 1

Calls 2

urlIsLocalFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected