Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function doWebSocket(url, headers = {}, isProxy) {
let ws;
if (isProxy) {
headers['via-proxy'] = 'true';
let agent = new tunnel.httpOverHttp({
proxy: {
hostname: SOCKE_PROXY_URL_OBJ.hostname,
port: SOCKE_PROXY_URL_OBJ.port
}
})
if (url.indexOf('wss') === 0) {
agent = new tunnel.httpsOverHttp({
rejectUnauthorized: false,
proxy: {
hostname: SOCKE_PROXY_URL_OBJ.hostname,
port: SOCKE_PROXY_URL_OBJ.port
}
})
}
function createHttpProxyAgent(host, port) {
return tunnel.httpOverHttp({
proxy: { host, port }
});
}
if (resource.cert) {
agentinfo.cert = resource.cert;
}
var isOverHTTPS = azureutil.urlIsHTTPS(proxy);
if (isHTTPS) {
if (isOverHTTPS) {
resource.agent = tunnel.httpsOverHttps(agentinfo);
} else {
resource.agent = tunnel.httpsOverHttp(agentinfo);
}
} else {
if (isOverHTTPS) {
resource.agent = tunnel.httpOverHttps(agentinfo);
} else {
resource.agent = tunnel.httpOverHttp(agentinfo);
}
}
} else if (isHTTPS) {
resource.agent = new https.Agent(resource);
}
};
async function request(target: string, body: Body, {configuration, headers, json, method = Method.GET}: Options) {
if (!configuration.get(`enableNetwork`))
throw new Error(`Network access have been disabled by configuration (${method} ${target})`);
const url = new URL(target);
if (url.protocol === `http:` && !micromatch.isMatch(url.hostname, configuration.get(`unsafeHttpWhitelist`)))
throw new Error(`Unsafe http requests must be explicitly whitelisted in your configuration (${url.hostname})`);
let agent;
const httpProxy = configuration.get(`httpProxy`);
const httpsProxy = configuration.get(`httpsProxy`);
if (url.protocol === `http:`)
agent = httpProxy
? tunnel.httpOverHttp(parseProxy(httpProxy))
: globalHttpAgent;
if (url.protocol === `https:`)
agent = httpsProxy
? tunnel.httpsOverHttp(parseProxy(httpsProxy))
: globalHttpsAgent;
const gotOptions: GotOptions = {agent, headers, method};
let hostname: string | undefined;
gotOptions.responseType = json
? `json`
: `buffer`;
if (body !== null) {
if (typeof body === `string` || Buffer.isBuffer(body)) {
export function createTunnel(isRequestHttps: boolean, isProxyHttps: boolean, tunnelOptions: tunnel.HttpsOverHttpsOptions): http.Agent | https.Agent {
if (isRequestHttps && isProxyHttps) {
return tunnel.httpsOverHttps(tunnelOptions);
} else if (isRequestHttps && !isProxyHttps) {
return tunnel.httpsOverHttp(tunnelOptions);
} else if (!isRequestHttps && isProxyHttps) {
return tunnel.httpOverHttps(tunnelOptions);
} else {
return tunnel.httpOverHttp(tunnelOptions);
}
}
const protocol = proxyUrl.protocol
if (!supportedProtocols.includes(protocol)) {
throw new Error(
`Only http and https protocols are supported (protocol: ${protocol})`
)
}
if (!proxyUrl.port) {
throw new Error(`port is missing from proxy url ${proxyUrl.toString()}`)
}
const proxy = {
host: proxyUrl.hostname,
port: parseInt(proxyUrl.port, 10),
}
return protocol === 'http:'
? tunnel.httpOverHttp({ proxy })
: tunnel.httpOverHttps({ proxy })
}
export function createTunnel(isRequestHttps: boolean, isProxyHttps: boolean, tunnelOptions: tunnel.HttpsOverHttpsOptions): http.Agent | https.Agent {
if (isRequestHttps && isProxyHttps) {
return tunnel.httpsOverHttps(tunnelOptions);
} else if (isRequestHttps && !isProxyHttps) {
return tunnel.httpsOverHttp(tunnelOptions);
} else if (!isRequestHttps && isProxyHttps) {
return tunnel.httpOverHttps(tunnelOptions);
} else {
return tunnel.httpOverHttp(tunnelOptions);
}
}
host: config.proxyHost,
port: config.proxyPort,
proxyAuth: config.proxyAuth
}
};
if (config.proxyScheme === 'https') {
if (!config.baseUri || config.baseUri.startsWith('https')) {
return tunnel.httpsOverHttps(options);
} else {
return tunnel.httpOverHttps(options);
}
} else if (!config.baseUri || config.baseUri.startsWith('https')) {
return tunnel.httpsOverHttp(options);
} else {
return tunnel.httpOverHttp(options);
}
}
port: proxyUrl.port
}
};
if (proxyUrl.username && proxyUrl.password) {
tunnelOptions.proxy.proxyAuth = `${proxyUrl.username}:${proxyUrl.password}`;
}
if (url.startsWith('https://')) {
if (proxy.startsWith('https://')) {
requestOptions.agent = tunnel.httpsOverHttps(tunnelOptions);
} else {
requestOptions.agent = tunnel.httpsOverHttp(tunnelOptions);
}
} else if (proxy.startsWith('https://')) {
requestOptions.agent = tunnel.httpOverHttps(tunnelOptions);
} else {
requestOptions.agent = tunnel.httpOverHttp(tunnelOptions);
}
}
}
return requestOptions;
}
};