How to use the proxy-agent function in proxy-agent

To help you get started, we’ve selected a few proxy-agent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / test / integration / proxy.spec.ts View on Github external
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) {
github youzan / zan-proxy / src / core / proxy / middleware / forward.ts View on Github external
private addProxyAgent(options: http.RequestOptions) {
    const customProxy = this.profileService.customProxy;
    if (customProxy) {
      // @ts-ignore
      options.agent = new ProxyAgent(customProxy);
    }
  }
github abmaonline / aemfed / src / update-check.ts View on Github external
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);
};
github vladimiry / ElectronMail / src / electron-main / api / endpoints-builders / general.ts View on Github external
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
github coralproject / talk / src / core / server / services / stories / scraper / scraper.ts View on Github external
) {
    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;
github sportradar / aws-azure-login / src / login.ts View on Github external
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({
github signalapp / Signal-Desktop / ts / updater / common.ts View on Github external
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,
  };
}
github DeltaEvo / proxy-scraper / src / worker.js View on Github external
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 }))
}

proxy-agent

Maps proxy protocols to `http.Agent` implementations

MIT
Latest version published 15 days ago

Package Health Score

85 / 100
Full package analysis

Popular proxy-agent functions