Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 9 Examples of "https-proxy-agent in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'https-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.

import View from 'Core/View';
import GlobeView from 'Core/Prefab/GlobeView';
import HttpsProxyAgent from 'https-proxy-agent';
import Coordinates from 'Core/Geographic/Coordinates';
import Renderer from './mock';

const renderer = new Renderer();
const threedTilesLayer = new GeometryLayer('3d-tiles-discrete-lod', new Group());

threedTilesLayer.name = 'DiscreteLOD';
threedTilesLayer.url = 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles-samples/master/tilesets/TilesetWithDiscreteLOD/tileset.json';
threedTilesLayer.protocol = '3d-tiles';
threedTilesLayer.overrideMaterials = true;  // custom cesium shaders are not functional

if (process.env.HTTPS_PROXY) {
    threedTilesLayer.networkOptions = { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) };
}

const p = { coord: new Coordinates('EPSG:4326', -75.6114, 40.03428, 0), heading: 180, range: 4000, tilt: 22 };
const viewer = new GlobeView(renderer.domElement, p, { renderer, noControls: true });

const context = {
    camera: viewer.camera,
    engine: viewer.mainLoop.gfxEngine,
    scheduler: viewer.mainLoop.scheduler,
    geometryLayer: threedTilesLayer,
    view: viewer,
};

describe('3Dtiles layer', function () {
    it('Add 3dtiles layer', function (done) {
        View.prototype.addLayer.call(viewer, threedTilesLayer).then((layer) => {
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]}`);
}
if (cafile) {
    // Can be a single certificate file path or multiple paths, comma separated.
    const caPathArr = cafile.split(',')
    caCerts = caCerts.concat(caPathArr.map((cafilePath) => fs.readFileSync(cafilePath.trim())))
  }

  if (caCerts.length > 0) {
    Object.assign(agentOptions, {
      rejectUnauthorized: true,
      ca: caCerts
    })
  }

  if (proxy) {
    return new HttpsProxyAgent(agentOptions)
  } else if (agentOptions.ca) {
    return new https.Agent(agentOptions)
  }
  return undefined
}
export async function fetchStream(url: string, config: Record = {}, proxy) {
    if (proxy || process.env.http_proxy) {
        config.agent = new HttpsProxyAgent(proxy || process.env.http_proxy)
    }
    // 解决中文编码问题
    const escapeUrl = new URL(url).toString()
    return _fetch(escapeUrl, config)
}
private performAPI = (url: string, headers: any = {}, body: any = {}, method: string, suppressErrors?: boolean) => {
    this.d(`${method} ${url}`)
    // Allow using a proxy configured through environmental variables
    // Remember that to avoid the error "Error: self signed certificate in certificate chain"
    // you should also do: "export NODE_TLS_REJECT_UNAUTHORIZED=0". See: https://github.com/request/request/issues/2061
    let agent: Agent | undefined = undefined
    let proxy = process.env.http_proxy || process.env.https_proxy
    if (proxy) {
      agent = new HttpsProxyAgent(proxy)
    }

    return this.fetch(
      url,
      {
        method,
        body,
        headers: {
          "Content-Type": "application/json",
          ...headers,
        },
        agent,
      },
      suppressErrors
    )
  }
} else if (this.repoCredentials.password) {
      headers["Authorization"] = `Basic ${new Buffer(
        this.repoCredentials.username + ":" + this.repoCredentials.password
      ).toString("base64")}`
    }

    const url = `${this.repoCredentials.host}/${path}`
    this.d(`${method} ${url}`)

    // Allow using a proxy configured through environmental variables
    // Remember that to avoid the error "Error: self signed certificate in certificate chain"
    // you should also do: "export NODE_TLS_REJECT_UNAUTHORIZED=0". See: https://github.com/request/request/issues/2061
    let agent: Agent | undefined = undefined
    let proxy = process.env.http_proxy || process.env.https_proxy
    if (proxy) {
      agent = new HttpsProxyAgent(proxy)
    }

    return this.fetch(
      url,
      {
        method,
        body,
        headers: {
          "Content-Type": "application/json",
          ...headers,
        },
        agent,
      },
      suppressErrors
    )
  }
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);
  }
}
setProxy(proxy) {
        if (validate.null(proxy)) {
            this.proxyAgent = null;
            return this;
        }
        validate.required(proxy, ['hostname', 'port'], 'Client.setProxy');
        this.proxyAgent = new HttpsProxyAgent(`${proxy.hostname}:${proxy.port}`);
        return this;
    }
}
        if (common_1.hasProperties(agentOptions) && url.startsWith('https:')) {
            let existingAgents;
            if (credentials.proxy)
                existingAgents = proxyAgents.get(credentials.proxy);
            else
                existingAgents = agents;
            if (existingAgents)
                agent = agents.find(agent => {
                    return !Object.keys(agentOptions).some(opt => agent.options[opt] !== agentOptions[opt]);
                });
            if (!agent) {
                if (credentials.proxy) {
                    if (!existingAgents)
                        proxyAgents.set(credentials.proxy, existingAgents = []);
                    existingAgents.push(agent = new https_proxy_agent_1.default(Object.assign({}, credentials.proxy)));
                }
                else {
                    agents.push(agent = (new https_1.Agent(agentOptions)));
                }
            }
        }
        this.debugLog(`${method} ${url}${writeCredentialLog(credentials)}`);
        if (credentials.basicAuth) {
            const urlObj = new url_1.URL(url);
            if (!urlObj.username && !urlObj.password) {
                ({ username: urlObj.username, password: urlObj.password } = credentials.basicAuth);
                requestUrl = urlObj.href;
            }
        }
        if (agent)
            options = Object.assign({ agent }, options);

Is your System Free of Underlying Vulnerabilities?
Find Out Now