How to use the proxy-from-env.getProxyForUrl function in proxy-from-env

To help you get started, we’ve selected a few proxy-from-env 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 TooTallNate / node-proxy-agent / index.js View on Github external
function connect (req, opts, fn) {
  var proxyOpts = this.proxy;
  var proxyUri = this.proxyUri;
  var proxyFn = this.proxyFn;

  // if we did not instantiate with a proxy, set one per request
  if (!proxyOpts) {
    var urlOpts = getProxyForUrl(opts);
    var proxy = mapOptsToProxy(urlOpts, opts);
    proxyOpts = proxy.opts;
    proxyUri = proxy.uri;
    proxyFn = proxy.fn;
  }

  // create the "key" for the LRU cache
  var key = proxyUri;
  if (opts.secureEndpoint) key += ' secure';

  // attempt to get a cached `http.Agent` instance first
  var agent = exports.cache.get(key);
  if (!agent) {
    // get an `http.Agent` instance from protocol-specific agent function
    agent = proxyFn(proxyOpts, opts.secureEndpoint);
    if (agent) {
github snyk / snyk / src / lib / request / request.ts View on Github external
let url = payload.url;

        if (payload.qs) {
          url = url + '?' + querystring.stringify(payload.qs);
          delete payload.qs;
        }

        const options: needle.NeedleOptions = {
          json: payload.json,
          headers: payload.headers,
          timeout: payload.timeout,
          // eslint-disable-next-line @typescript-eslint/camelcase
          follow_max: 5,
        };

        const proxyUri = getProxyForUrl(url);
        if (proxyUri) {
          snykDebug('using proxy:', proxyUri);
          options.agent = (new ProxyAgent(proxyUri) as unknown) as Agent;
        } else {
          snykDebug('not using proxy');
        }

        if (global.ignoreUnknownCA) {
          debug('Using insecure mode (ignore unkown certificate authority)');
          options.rejectUnauthorized = false;
        }

        needle.request(method, url, data, options, (err, res, respBody) => {
          debug(err);
          debug(
            'response (%s): ',
github cypress-io / cypress / packages / server / lib / util / agent.ts View on Github external
createConnection (options, cb) {
    if (process.env.HTTPS_PROXY) {
      const proxy = getProxyForUrl(options.href)

      if (proxy) {
        options.proxy = proxy

        return this.createProxiedConnection(options, cb)
      }
    }

    // @ts-ignore
    cb(null, super.createConnection(options))
  }
github snyk / snyk / src / lib / protect / fetch-patch.js View on Github external
return new Promise(function (resolve, reject) {
    var options = {};
    var proxyUri = getProxyForUrl(url);
    if (proxyUri) {
      debug('Using proxy: ', proxyUri);
      options.agent = new ProxyAgent(proxyUri);
    }

    needle.get(url, options)
      .on('response', function (response) {
        if (response.statusCode >= 400) {
          if (!attempts) {
            var err = new Error('Failed to fetch patch file');
            analytics.add('patch-fetch-fail', {
              message: err.message,
              code: response.statusCode,
            });
            return reject(err);
          }
github cypress-io / cypress / packages / server / lib / util / agent.ts View on Github external
createSocket (req, options, cb) {
    if (process.env.HTTP_PROXY) {
      const proxy = getProxyForUrl(options.href)

      if (proxy) {
        options.proxy = proxy

        return this._createProxiedSocket(req, options, cb)
      }
    }

    super.createSocket(req, options, cb)
  }
github puppeteer / puppeteer / lib / BrowserFetcher.js View on Github external
function httpRequest(url, method, response) {
  /** @type {Object} */
  let options = URL.parse(url);
  options.method = method;

  const proxyURL = getProxyForUrl(url);
  if (proxyURL) {
    if (url.startsWith('http:')) {
      const proxy = URL.parse(proxyURL);
      options = {
        path: options.href,
        host: proxy.hostname,
        port: proxy.port,
      };
    } else {
      /** @type {Object} */
      const parsedProxyURL = URL.parse(proxyURL);
      parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:';

      options.agent = new ProxyAgent(parsedProxyURL);
      options.rejectUnauthorized = false;
    }
github puppeteer / puppeteer / experimental / puppeteer-firefox / lib / BrowserFetcher.js View on Github external
function httpRequest(url, method, response) {
  /** @type {Object} */
  const options = URL.parse(url);
  options.method = method;

  const proxyURL = getProxyForUrl(url);
  if (proxyURL) {
    /** @type {Object} */
    const parsedProxyURL = URL.parse(proxyURL);
    parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:';

    options.agent = new ProxyAgent(parsedProxyURL);
    options.rejectUnauthorized = false;
  }

  const requestCallback = res => {
    if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location)
      httpRequest(res.headers.location, method, response);
    else
      response(res);
  };
  const request = options.protocol === 'https:' ?
github getsentry / sentry-cli / scripts / install.js View on Github external
const arch = os.arch();
  const platform = os.platform();
  const outputPath = helper.getPath();

  const downloadUrl = getDownloadUrl(platform, arch);
  if (!downloadUrl) {
    return Promise.reject(new Error(`unsupported target ${platform}-${arch}`));
  }

  const cachedPath = getCachedPath(downloadUrl);
  if (fs.existsSync(cachedPath)) {
    copyFileSync(cachedPath, outputPath);
    return Promise.resolve();
  }

  const proxyUrl = Proxy.getProxyForUrl(downloadUrl);
  const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : null;

  return fetch(downloadUrl, {
    agent,
    compress: false,
    headers: {
      'accept-encoding': 'gzip, deflate, br',
    },
    redirect: 'follow',
  }).then(response => {
    if (!response.ok) {
      throw new Error(`Received ${response.status}: ${response.statusText}`);
    }

    const contentEncoding = response.headers.get('content-encoding');
    let decompressor;
github getgauge / taiko / lib / browserFetcher.js View on Github external
function httpRequest(url, method, response) {
  /** @type {Object} */
  const options = URL.parse(url);
  options.method = method;

  const proxyURL = getProxyForUrl(url);
  if (proxyURL) {
    /** @type {Object} */
    const parsedProxyURL = URL.parse(proxyURL);
    parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:';

    options.agent = new ProxyAgent(parsedProxyURL);
    options.rejectUnauthorized = false;
  }

  const driver = options.protocol === 'https:' ? 'https' : 'http';
  const request = require(driver).request(options, res => {
    if (
      res.statusCode >= 300 &&
      res.statusCode < 400 &&
      res.headers.location
    ) {

proxy-from-env

Offers getProxyForUrl to get the proxy URL for a URL, respecting the *_PROXY (e.g. HTTP_PROXY) and NO_PROXY environment variables.

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis

Popular proxy-from-env functions