Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'proxy-agent' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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({
const EVENTS_TABLE = process.env.GTM_DYNAMO_TABLE_EVENTS;
let INITIAL_DATA = [];
let EventMetricStream;
let elastic;
if (process.env.GTM_ELASTIC_HOST && process.env.GTM_ELASTIC_PORT) {
elastic = new elasticsearch.Client({
host: `${process.env.GTM_ELASTIC_HOST}:${process.env.GTM_ELASTIC_PORT}`,
log: 'info'
});
}
if (process.env.IAM_ENABLED) {
AWS.config.update({
httpOptions: {
agent: proxy(process.env.HTTP_PROXY)
}
});
}
async function configureRoutes(app) {
let ddb;
if (process.env.GTM_DYNAMO_VPCE) {
console.log('Configuring DynamoDB to use VPC Endpoint');
ddb = new AWS.DynamoDB({
httpOptions: {
agent: new https.Agent()
}
});
} else {
console.log('Configuring DynamoDB to use Global AWS Config');
ddb = new AWS.DynamoDB();
function create(agentId) {
if (!agentId) console.warn('agentId is not set.');
let CWLogOptions = {
region: process.env.GTM_AWS_REGION
};
if (process.env.IAM_ENABLED) {
CWLogOptions = {
region: process.env.GTM_AWS_REGION,
//accessKeyId: process.env.AWS_ACCESS_KEY_ID,
//secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
//sessionToken: process.env.AWS_SECURITY_TOKEN,
httpOptions: {
agent: proxy(process.env.HTTP_PROXY)
}
};
}
let cloudWatchStream = new CWLogsWritable({
logGroupName: getLogGroupMap()['gtmAgent'],
logStreamName: 'AGENT_ID=' + agentId,
cloudWatchLogsOptions: CWLogOptions
}).on('error', console.error);
janitorInterval = setInterval(streamJanitor, 60000);
let bunyanConf = {
name: agentId.substring(0, 7),
streams: [
{
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 }))
}