MCPcopy
hub / github.com/socketio/socket.io / url

Function url

packages/socket.io/client-dist/socket.io.js:3009–3053  ·  view source on GitHub ↗

* URL parser. * * @param uri - url * @param path - the request path of the connection * @param loc - An object meant to mimic window.location. * Defaults to window.location. * @public

(uri)

Source from the content-addressed store, hash-verified

3007 * @public
3008 */
3009 function url(uri) {
3010 var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
3011 var loc = arguments.length > 2 ? arguments[2] : undefined;
3012 var obj = uri;
3013 // default to window.location
3014 loc = loc || typeof location !== "undefined" && location;
3015 if (null == uri) uri = loc.protocol + "//" + loc.host;
3016 // relative path support
3017 if (typeof uri === "string") {
3018 if ("/" === uri.charAt(0)) {
3019 if ("/" === uri.charAt(1)) {
3020 uri = loc.protocol + uri;
3021 } else {
3022 uri = loc.host + uri;
3023 }
3024 }
3025 if (!/^(https?|wss?):\/\//.test(uri)) {
3026 debug$3("protocol-less url %s", uri);
3027 if ("undefined" !== typeof loc) {
3028 uri = loc.protocol + "//" + uri;
3029 } else {
3030 uri = "https://" + uri;
3031 }
3032 }
3033 // parse
3034 debug$3("parse %s", uri);
3035 obj = parse(uri);
3036 }
3037 // make sure we treat `localhost:80` and `localhost` equally
3038 if (!obj.port) {
3039 if (/^(http|ws)$/.test(obj.protocol)) {
3040 obj.port = "80";
3041 } else if (/^(http|ws)s$/.test(obj.protocol)) {
3042 obj.port = "443";
3043 }
3044 }
3045 obj.path = obj.path || "/";
3046 var ipv6 = obj.host.indexOf(":") !== -1;
3047 var host = ipv6 ? "[" + obj.host + "]" : obj.host;
3048 // define unique id
3049 obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
3050 // define href
3051 obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port);
3052 return obj;
3053 }
3054
3055 var withNativeArrayBuffer = typeof ArrayBuffer === "function";
3056 var isView = function isView(obj) {

Callers 2

lookupFunction · 0.90
lookupFunction · 0.70

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected