MCPcopy
hub / github.com/ampproject/amphtml / getSourceUrl

Function getSourceUrl

src/url.js:493–526  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

491 * @return {string}
492 */
493export function getSourceUrl(url) {
494 url = urlAsLocation(url);
495
496 // Not a proxy URL - return the URL itself.
497 if (!isProxyOrigin(url)) {
498 return url.href;
499 }
500
501 // A proxy URL.
502 // Example path that is being matched here.
503 // https://cdn.ampproject.org/c/s/www.origin.com/foo/
504 // The /s/ is optional and signals a secure origin.
505 const path = url.pathname.split('/');
506 const prefix = path[1];
507 userAssert(
508 SERVING_TYPE_PREFIX.has(prefix),
509 'Unknown path prefix in url %s',
510 url.href
511 );
512 const domainOrHttpsSignal = path[2];
513 const origin =
514 domainOrHttpsSignal == 's'
515 ? 'https://' + decodeURIComponent(path[3])
516 : 'http://' + decodeURIComponent(domainOrHttpsSignal);
517 // Sanity test that what we found looks like a domain.
518 userAssert(origin.indexOf('.') > 0, 'Expected a . in origin %s', origin);
519 path.splice(1, domainOrHttpsSignal == 's' ? 3 : 2);
520 return (
521 origin +
522 path.join('/') +
523 removeAmpJsParamsFromSearch(url.search) +
524 (url.hash || '')
525 );
526}
527
528/**
529 * Returns the source origin of an AMP document for documents served

Callers 15

testOriginFunction · 0.90
resolveUrlAttrFunction · 0.90
getMethod · 0.90
sourceUrlMethod · 0.90
initializeMethod · 0.90
doPassMethod · 0.90
getSourceUrlMethod · 0.90
medianetFunction · 0.90
openChannelAndStart_Method · 0.90
validatePageFunction · 0.90

Calls 5

userAssertFunction · 0.90
urlAsLocationFunction · 0.85
isProxyOriginFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected