How to use http-proxy-agent - 5 common examples

To help you get started, we’ve selected a few http-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 auth0 / auth0-deploy-cli / src / index.js View on Github external
async function run() {
  // Run command
  const cmd = commands[params._[0]];

  // TODO: Prob a native/better way to enforce command choices in yargs.
  if (!cmd) {
    log.error(`Command ${params._[0]} not supported\n`);
    args.showHelp();
    process.exit(1);
  }

  // Monkey Patch the superagent for proxy use
  const proxy = params.proxy_url;
  if (proxy) {
    const proxyAgent = new HttpProxyAgent(proxy);
    const proxyAgentSsl = new HttpsProxyAgent(proxy);
    const OrigRequest = superagent.Request;
    superagent.Request = function RequestWithAgent(method, url) {
      const req = new OrigRequest(method, url);
      log.info(`Setting proxy for ${method} to ${url}`);
      if (url.startsWith('https')) return req.agent(proxyAgentSsl);
      return req.agent(proxyAgent);
    };
  }

  log.debug(`Start command ${params._[0]}`);
  await cmd(params);
  log.debug(`Finished command ${params._[0]}`);
}
github poooi / poi / lib / proxy.es View on Github external
}
        options.agent = this.socksAgents[uri]
        break
      }
      // HTTP Request via HTTP proxy
      case 'http': {
        const host = config.get('proxy.http.host', '127.0.0.1')
        const port = config.get('proxy.http.port', 8118)
        const requirePassword = config.get('proxy.http.requirePassword', false)
        const username = config.get('proxy.http.username', '')
        const password = config.get('proxy.http.password', '')
        const useAuth = requirePassword && username !== '' && password !== ''
        const strAuth = `${username}:${password}@`
        const uri = `http://${useAuth ? strAuth : ''}${host}:${port}`
        if (!this.httpAgents[uri]) {
          this.httpAgents[uri] = new HttpProxyAgent(uri)
        }
        options.agent = this.httpAgents[uri]
        break
      }
      // PAC
      case 'pac': {
        const uri = config.get('proxy.pacAddr')
        if (!this.pacAgents[uri]) {
          this.pacAgents[uri] = new PacProxyAgent(uri)
        }
        options.agent = this.pacAgents[uri]
        break
      }
    }
    return options
  }
github danger / danger-js / source / api / fetch.ts View on Github external
// output.concat([init.body])
    }

    if (typeof url === "string") {
      output.push(url)
    }

    d(output.join(" "))
  }

  let agent = init.agent
  const proxy = process.env["HTTPS_PROXY"] || process.env["HTTP_PROXY"]

  if (!agent && proxy) {
    let secure = url.toString().startsWith("https")
    init.agent = secure ? new HttpsProxyAgent(proxy) : new HttpProxyAgent(proxy)
  }

  return retryableFetch(url, init).then(async (response: node_fetch.Response) => {
    // Handle failing errors
    if (!suppressErrorReporting && !response.ok) {
      // we should not modify the response when an error occur to allow body stream to be read again if needed
      let clonedResponse = response.clone()
      warn(`Request failed [${clonedResponse.status}]: ${clonedResponse.url}`)
      let responseBody = await clonedResponse.text()
      try {
        // tries to pretty print the JSON response when possible
        const responseJSON = await JSON.parse(responseBody.toString())
        warn(`Response: ${JSON.stringify(responseJSON, null, "  ")}`)
      } catch (e) {
        warn(`Response: ${responseBody}`)
      }
github elastic / kibana / src / cli_plugin / install / downloaders / http.js View on Github external
function getProxyAgent(sourceUrl, logger) {
  const proxy = getProxyForUrl(sourceUrl);

  if (!proxy) {
    return null;
  }

  logger.log(`Picked up proxy ${proxy} from environment variable.`);

  if (/^https/.test(sourceUrl)) {
    return new HttpsProxyAgent(proxy);
  } else {
    return new HttpProxyAgent(proxy);
  }
}
github makeflow / remote-workspace / src / client-host / main.ts View on Github external
main(async () => {
  const apiServer = new Server({
    port: config.port,
  });

  let httpProxyUrl = process.env['HTTP_PROXY'];

  if (httpProxyUrl) {
    console.info(`Using proxy ${httpProxyUrl}.`);
    agent = new HttpProxyAgent(httpProxyUrl);
  }

  await apiServer.register(H2O2);

  apiServer.route({
    method: 'GET',
    path: '/api/client-host-version',
    handler() {
      return {
        data: version,
      };
    },
  });

  apiServer.route({
    method: 'POST',

http-proxy-agent

An HTTP(s) proxy `http.Agent` implementation for HTTP

MIT
Latest version published 10 days ago

Package Health Score

83 / 100
Full package analysis

Popular http-proxy-agent functions