Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

better-http-proxy-agent

insightfuls20MIT1.0.4

An agent for HTTP through an HTTP(S) proxy server

https, http, proxy, http proxy, https proxy, agent, connection, pool, pooling, connection pool, connection pooling, timeout, TLS, SSL, client, certificate, client certificate, basic, authentication, basic authentication

readme

better-http-proxy-agent

An agent for HTTP through an HTTP(S) proxy server.

This is based on http-proxy-agent but instead of building on a custom base class it extends the NodeJS http.Agent or https.Agent to leverage core functionality such as connection pooling (all connections are to the proxy so there is just one bucket in the pool) and TLS session resumption.

Basic usage

npm install better-http-proxy-agent
const { createAgent } = require('better-http-proxy-agent');
const fs = require('fs');
const http = require('http');

/*
 * Options suitable for the base `http(s).Agent`.
 */
const agentOptions = {
    keepAlive: true,
    timeout: 55000, // for keepAlive
    maxSockets: 100,
    maxFreeSockets: 10,
    maxCachedSessions: 200
};

/*
 * Options suitable for `http(s).request`/`net.connect`/`tls.connect`. These
 * are used to connect to the proxy server.
 *
 * You should provide the `host` and `port` of the proxy here (unless you want
 * the default `localhost`).
 *
 * `protocol` will default to `http:`. If you need to connect to the proxy over
 * HTTPS, set `protocol` to `https:`. `http.Agent` or `https.Agent` will be
 * used accordingly.
 *
 * You can provide `auth` here, which will produce a `Proxy-Authorization`
 * header.
 */
const connectionOptions = {
    protocol: "https:",
    host: "proxy.example.com",
    port: 3128,
    timeout: 5000, // for in-flight requests
    cert: fs.readFileSync("proxy_auth_cert.pem"),
    key: fs.readFileSync("proxy_auth_key.pem"),
    passphrase: "secret"
};

const agent = createAgent(agentOptions, connectionOptions);

http.get("http://www.example.com/", {
    agent
});

Licence

MIT.