UNPKG

@dioxide-js/silas

Version:

RPC utility for Silas

1 lines 6.26 kB
{"version":3,"file":"index.mjs","sources":["../../../../node_modules/proxy-from-env/index.js"],"sourcesContent":["'use strict';\n\nvar parseUrl = require('url').parse;\n\nvar DEFAULT_PORTS = {\n ftp: 21,\n gopher: 70,\n http: 80,\n https: 443,\n ws: 80,\n wss: 443,\n};\n\nvar stringEndsWith = String.prototype.endsWith || function(s) {\n return s.length <= this.length &&\n this.indexOf(s, this.length - s.length) !== -1;\n};\n\n/**\n * @param {string|object} url - The URL, or the result from url.parse.\n * @return {string} The URL of the proxy that should handle the request to the\n * given URL. If no proxy is set, this will be an empty string.\n */\nfunction getProxyForUrl(url) {\n var parsedUrl = typeof url === 'string' ? parseUrl(url) : url || {};\n var proto = parsedUrl.protocol;\n var hostname = parsedUrl.host;\n var port = parsedUrl.port;\n if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {\n return ''; // Don't proxy URLs without a valid scheme or host.\n }\n\n proto = proto.split(':', 1)[0];\n // Stripping ports in this way instead of using parsedUrl.hostname to make\n // sure that the brackets around IPv6 addresses are kept.\n hostname = hostname.replace(/:\\d*$/, '');\n port = parseInt(port) || DEFAULT_PORTS[proto] || 0;\n if (!shouldProxy(hostname, port)) {\n return ''; // Don't proxy URLs that match NO_PROXY.\n }\n\n var proxy =\n getEnv('npm_config_' + proto + '_proxy') ||\n getEnv(proto + '_proxy') ||\n getEnv('npm_config_proxy') ||\n getEnv('all_proxy');\n if (proxy && proxy.indexOf('://') === -1) {\n // Missing scheme in proxy, default to the requested URL's scheme.\n proxy = proto + '://' + proxy;\n }\n return proxy;\n}\n\n/**\n * Determines whether a given URL should be proxied.\n *\n * @param {string} hostname - The host name of the URL.\n * @param {number} port - The effective port of the URL.\n * @returns {boolean} Whether the given URL should be proxied.\n * @private\n */\nfunction shouldProxy(hostname, port) {\n var NO_PROXY =\n (getEnv('npm_config_no_proxy') || getEnv('no_proxy')).toLowerCase();\n if (!NO_PROXY) {\n return true; // Always proxy if NO_PROXY is not set.\n }\n if (NO_PROXY === '*') {\n return false; // Never proxy if wildcard is set.\n }\n\n return NO_PROXY.split(/[,\\s]/).every(function(proxy) {\n if (!proxy) {\n return true; // Skip zero-length hosts.\n }\n var parsedProxy = proxy.match(/^(.+):(\\d+)$/);\n var parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;\n var parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0;\n if (parsedProxyPort && parsedProxyPort !== port) {\n return true; // Skip if ports don't match.\n }\n\n if (!/^[.*]/.test(parsedProxyHostname)) {\n // No wildcards, so stop proxying if there is an exact match.\n return hostname !== parsedProxyHostname;\n }\n\n if (parsedProxyHostname.charAt(0) === '*') {\n // Remove leading wildcard.\n parsedProxyHostname = parsedProxyHostname.slice(1);\n }\n // Stop proxying if the hostname ends with the no_proxy host.\n return !stringEndsWith.call(hostname, parsedProxyHostname);\n });\n}\n\n/**\n * Get the value for an environment variable.\n *\n * @param {string} key - The name of the environment variable.\n * @return {string} The value of the environment variable.\n * @private\n */\nfunction getEnv(key) {\n return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';\n}\n\nexports.getProxyForUrl = getProxyForUrl;\n"],"names":[],"mappings":";;;;;;;;;AAEA,CAAA,IAAI,QAAQ,GAAG,UAAc,CAAC,KAAK;;AAEnC,CAAA,IAAI,aAAa,GAAG;GAClB,GAAG,EAAE,EAAE;GACP,MAAM,EAAE,EAAE;GACV,IAAI,EAAE,EAAE;GACR,KAAK,EAAE,GAAG;GACV,EAAE,EAAE,EAAE;GACN,GAAG,EAAE,GAAG;EACT;;CAED,IAAI,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,EAAE;AAC9D,GAAE,OAAO,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;AAChC,KAAI,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,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