Path: blob/master/node_modules/axios/lib/helpers/isURLSameOrigin.js
1126 views
'use strict';12var utils = require('./../utils');34module.exports = (5utils.isStandardBrowserEnv() ?67// Standard browser envs have full support of the APIs needed to test8// whether the request URL is of the same origin as current location.9(function standardBrowserEnv() {10var msie = /(msie|trident)/i.test(navigator.userAgent);11var urlParsingNode = document.createElement('a');12var originURL;1314/**15* Parse a URL to discover it's components16*17* @param {String} url The URL to be parsed18* @returns {Object}19*/20function resolveURL(url) {21var href = url;2223if (msie) {24// IE needs attribute set twice to normalize properties25urlParsingNode.setAttribute('href', href);26href = urlParsingNode.href;27}2829urlParsingNode.setAttribute('href', href);3031// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils32return {33href: urlParsingNode.href,34protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',35host: urlParsingNode.host,36search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',37hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',38hostname: urlParsingNode.hostname,39port: urlParsingNode.port,40pathname: (urlParsingNode.pathname.charAt(0) === '/') ?41urlParsingNode.pathname :42'/' + urlParsingNode.pathname43};44}4546originURL = resolveURL(window.location.href);4748/**49* Determine if a URL shares the same origin as the current location50*51* @param {String} requestURL The URL to test52* @returns {boolean} True if URL shares the same origin, otherwise false53*/54return function isURLSameOrigin(requestURL) {55var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;56return (parsed.protocol === originURL.protocol &&57parsed.host === originURL.host);58};59})() :6061// Non standard browser envs (web workers, react-native) lack needed support.62(function nonStandardBrowserEnv() {63return function isURLSameOrigin() {64return true;65};66})()67);686970