/*
Prepend a '/' to relative url used for api entry point since they are resolved from
the root

@param url
@param host
@returns {string} an absolute url
182576
function toAbsoluteUrl(url, host) {

                    return isAbsolute(url) ? url : (startWithSlash(url) ? host + url : host + '/' + url);

                }
203329
public static String normalizeHost(String host) {
        // if it is normalized IPv6 or could not be IPv6, return
        if (host.isEmpty() || host.charAt(0) == '[' || host.indexOf(':') < 0)
            return host;

        // normalize with [ ]
        return "[" + host + "]";
    }
100403
function( url ) {
            var match = url.match(/^([a-z]+:)\/\//i);
            if ( match === null ) {
                // Relative URL, retrive the protocol from window.location
                return window.location.protocol;
            }
            return match[1].toLowerCase();
        }
539767
function translateUrl (url) {
  const RE = new RegExp('^[./]');
  if (RE.test(url)) {
    const fileUrl = 'file://' + path.join(process.cwd(), url);
    console.log('Relative filename detected -- translating to ' + fileUrl);
    return fileUrl;
  } else {
    return url;
  }
}
148030
function setHost(uri) {
  if (uri.auth || uri.hostname || uri.port) {
    uri.host = '';
    if (uri.auth) uri.host += uri.auth + '@';
    if (uri.hostname) uri.host += uri.hostname;
    if (uri.port) uri.host += ':' + uri.port;
  }
}
246336
function buildModelUrl (protocol, host, apiRoot, modelName, id) {
  var result

  try {
    result = url.format({
      protocol: protocol,
      host: host,
      pathname: url.resolve('/', [apiRoot, modelName, id].join('/'))
    })
  } catch (e) {
    return ''
  }

  return result
}
366592
function resolveURL(url) {
		return new URI(url).absoluteTo(new URI(document.baseURI).search("")).toString();
	}
823691
public static String urlToHost(String url) {
		String lcUrl = url.toLowerCase();
		if(lcUrl.startsWith(DNS_SCHEME)) {
			return lcUrl.substring(DNS_SCHEME.length());
		}
		for(String scheme : ALL_SCHEMES) {
			if(lcUrl.startsWith(scheme)) {
				int authorityIdx = scheme.length();

				Matcher m = 
					HOST_REGEX_SIMPLE.matcher(lcUrl.substring(authorityIdx));
				if(m.find()) {
					return m.group(1);
				}
			}
		}
		return url;
	}
640883
function urlToUri(url) {
  let parts;

  if (!isUrl(url)) {
    throw new Error('Invalid url ' + url);
  }
  parts = urlParse.parse(url);

  return `${parts.hostname}${decodeURIComponent(parts.path)}`;
}
1199439
function getHost(url) {
        var uri = window.document.createElement('a');

        if (isAbsolute(url) || startWithSlash(url)) {

            uri.href = url;

            return (uri.protocol || window.location.protocol) + '//' + (uri.host || window.location.host);

        }
    }
850016
public void setHttpProxy(String host) {
    setProxyValue(HTTP_SERVER, host);
    setProxyValue(USE_HTTP, host != null);
  }
808928
function(baseUrl, relUrl) {
        var i  = baseUrl.lastIndexOf('/');
        if (i === -1) {
            // this url is relative itself without any slashes
            return relUrl;
        }
        baseUrl = baseUrl.slice(0, i);
        return baseUrl + '/' + relUrl;
    }
303390
function formatUrl($url)
    {
        if (! $this->isUrl($url)) {
            return null;
        }
        $url = trim($url);
        $url = str_replace(' ', '+', $url);
        $parse = parse_url($url);
        strtolower($parse['scheme']);
        strtolower($parse['host']);
        return $this->buildUrl($parse);
    }
731821
def with_url(self, url):
        
        self.url = URL(url)
        self.header["Host"] = self.url.host
        return self
458813
function (host) {
        /*
        * For Host match, we are considering the port with the host, hence we are using getRemote() instead of getHost()
        * We need to address three cases for the host urlStr
        * 1. * It matches all the host + protocol,  hence we are not having any parsing logic for it.
        * 2. *.foo.bar.com Here the prefix could be anything but it should end with foo.bar.com
        * 3. foo.bar.com This is the absolute matching needs to done.
        */
        var matchRegexObject = this._matchPatternObject;
        return (
            this.matchAnyHost(matchRegexObject) ||
            this.matchAbsoluteHostPattern(matchRegexObject, host) ||
            this.matchSuffixHostPattern(matchRegexObject, host)
        );
    }
156491
function formatURL(xStartHost, xurl, url, replaceHash, resultHost) {
    if (typeof url !== 'string') {
        return 'badurl:' + url;
    };

    if (typeof xurl !== 'string') {
        xurl = xurl.href;
    };

    if (!/[\/\.\:]/.test(url)) {
        if (replaceHash && replaceHash !== true) {
            var x = replaceHash[url];
            if (x !== und) {
                return !resultHost ? x.value : x;
            };
        };
    };

    var url = normalizeURL(url);

    if (/^\/([^\/]|$)/.test(url)) {
        if (xStartHost && xurl.indexOf(xStartHost) === 0) {
            url = xStartHost + url;
        };
    };

    url = aliasURL(URL.resolve(xurl, url), false);

    if (replaceHash && replaceHash !== true) {
        var und;
        var x = replaceHash[url];
        if (x !== und) {
            return !resultHost ? x.value : x;
        };

        var s = url.replace(/[^\/]+$/, '');
        for(; /^(file|https?):\/\/./.test(s);  s = s.replace(/[^\/]+\/+$/, '') ) {
            var x = replaceHash[s];
            if (x !== und) {
                if (x.type === 'path') {
                    var value = x.value + url.substring(s.length);
                    return !resultHost ? value : {
                        value: value,
                        host: x.host,
                        type: x.type
                    };

                } else {
                    return !resultHost ? x.value : x;
                };
            };
        };
    };

    return !resultHost ? url : {
        type: 'path',
        host: xStartHost,
        value: url
    };
}
1291342
function (host, reInit) {
        if (_.isEmpty(host.id) || !_.isString(host.id)) {
            throw new Error("Host configuration is invalid. Host id is missing or not a string");
        }
        if (_.isEmpty(host.host)) {
            throw new Error("Host configuration is invalid. Host is missing");
        }

        if (_.isString(host.host)) {
            host.host = [host.host];
        }

        if (!_.isArray(host.host)) {
            throw new Error("Host configuration is invalid. Host should be array or string");
        }

        var router = new express.Router();

        if (reInit === false) {
            // Check if host is already defined. Use same router instance to merge routes
            for (var index in _vhosts) {
                for (var vh in _vhosts[index]["host"]) {
                    if (_vhosts[index]["host"][vh] == host.host) {
                        router = _vhosts[index]["router"];
                    }
                }
            }
        }

        _vhosts[host.id] = {
            host: host.host,
            router: router,
            http: !host.listener ? true : host.listener && host.listener.http || null,
            https: !host.listener ? true : host.listener && host.listener.https || null
        };

        _applyRouterConfig(_vhosts[host.id]["router"]);
        _customInitFuncton(_vhosts[host.id]["router"]);
    }