Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
proxy.on("connect", (req, clientSocket, head) => {
const serverUrl = new URL(`http://${req.url}`);
const serverSocket = net.connect(
parseInt(serverUrl.port, 10),
serverUrl.hostname,
() => {
clientSocket.write("HTTP/1.1 200 Connection Established\r\n" + "Proxy-agent: Node.js-Proxy\r\n" + "\r\n");
serverSocket.write(head);
serverSocket.pipe(clientSocket);
clientSocket.pipe(serverSocket);
}
);
});
const proxyPort = 8989;
const agent = new ProxyAgent(`http://127.0.0.1:${8989}`);
it("nativeApi Client Should successfully execute request", async function() {
return new Promise((resolve, reject) => {
proxy.listen(proxyPort, "127.0.0.1", async () => {
try {
const client = new CosmosClient({
endpoint,
auth: { masterKey },
agent
});
// create database
await client.databases.create({
id: addEntropy("ProxyTest")
});
resolve();
} catch (err) {
private addProxyAgent(options: http.RequestOptions) {
const customProxy = this.profileService.customProxy;
if (customProxy) {
// @ts-ignore
options.agent = new ProxyAgent(customProxy);
}
}
const loadPackage = (url: string, packageInfo: any) => {
const userAgent = `Mozilla/5.0 (${process.platform}; ${
process.arch
}) Node.js/${process.version.slice(1)} ${packageInfo.name}/${
packageInfo.version
}`;
// Determine proxy
const proxyAddress =
process.env.http_proxy ||
process.env.HTTP_PROXY ||
process.env.https_proxy ||
process.env.HTTPS_PROXY;
const proxyAgent = proxyAddress ? new ProxyAgent(proxyAddress) : undefined;
const options = {
agent: proxyAgent,
headers: {
"User-Agent": userAgent
},
json: true,
timeout: 2000
};
return rpn(url, options);
};
return async () => {
const {updateCheck: {releasesUrl, proxy}} = await ctx.configStore.readExisting();
const response = await fetch(
releasesUrl,
{
method: "GET",
timeout: UPDATE_CHECK_FETCH_TIMEOUT,
...(
proxy && {
agent: new ProxyAgent(proxy) as unknown as import("http").Agent,
}
),
},
);
if (!response.ok) {
// https://developer.github.com/v3/#rate-limiting
const rateLimitResetHeaderValue = Number(
response.headers.get("X-RateLimit-Reset"),
);
const rateLimitError = (
response.status === 403
&&
!isNaN(rateLimitResetHeaderValue)
&&
rateLimitResetHeaderValue > 0
) {
const log = this.log.child({ storyURL: url }, true);
// Abort the scrape request after the timeout is reached.
const { controller, timeout } = abortAfter(abortAfterMilliseconds);
const options: RequestInit = {
headers: {
"User-Agent": `Talk Scraper/${version}`,
},
signal: controller.signal,
};
if (proxyURL) {
// Force the type here because there's a slight mismatch.
options.agent = (new ProxyAgent(
proxyURL
) as unknown) as RequestInit["agent"];
log.debug("using proxy for scrape");
}
const start = Date.now();
log.debug("starting scrape of Story");
try {
const res = await fetch(url, options);
if (!res.ok || res.status !== 200) {
log.warn(
{ statusCode: res.status, statusText: res.statusText },
"scrape failed with non-200 status code"
);
return null;
async _assumeRoleAsync(
profileName: string,
assertion: string,
role: Role,
durationHours: number,
awsNoVerifySsl: boolean,
region: string | undefined
): Promise {
console.log(`Assuming role ${role.roleArn}`);
if (process.env.https_proxy) {
AWS.config.update({
httpOptions: {
agent: proxy(process.env.https_proxy)
}
});
}
if (awsNoVerifySsl) {
AWS.config.update({
httpOptions: {
agent: new https.Agent({
rejectUnauthorized: false
})
}
});
}
if (region) {
AWS.config.update({
function getGotOptions(): GotOptions {
const ca = getCertificateAuthority();
const proxyUrl = getProxyUrl();
const agent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
return {
agent,
ca,
headers: {
'Cache-Control': 'no-cache',
'User-Agent': 'Signal Desktop (+https://signal.org/download)',
},
useElectronNet: false,
};
}
function testProxy({ url, method, proxy, timeout }) {
log('testing %s with proxy %s and %s ms of timeout', url, proxy, timeout)
const startTime = Date.now()
const p = parse(proxy)
p.timeout = timeout
fetch(url, {
method: method || 'GET',
agent: new ProxyAgent(p),
timeout
})
.then(res => {
if (page) {
return res.text().then(p => {
if (p != page) {
const e = new Error('Page content missmatch')
e.type = 'missmatch'
throw e
}
})
}
})
.then(() => process.send({ working: true, time: Date.now() - startTime }))
.catch(error => process.send({ error, working: false }))
}