https://github.com/vweevers/auto-http-agent
Create http agent for HTTP(S)_PROXY proxies and/or keepAlive.
https://github.com/vweevers/auto-http-agent
agent http http-proxy https https-proxy no-proxy nodejs npm-package
Last synced: 2 months ago
JSON representation
Create http agent for HTTP(S)_PROXY proxies and/or keepAlive.
- Host: GitHub
- URL: https://github.com/vweevers/auto-http-agent
- Owner: vweevers
- License: mit
- Created: 2020-12-13T16:44:09.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-11-01T12:31:50.000Z (over 2 years ago)
- Last Synced: 2025-10-27T04:39:03.214Z (5 months ago)
- Topics: agent, http, http-proxy, https, https-proxy, no-proxy, nodejs, npm-package
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auto-http-agent
**Create an [http agent](https://nodejs.org/api/http.html#http_class_http_agent) for proxies and/or keepAlive. Returns a proxy if a given URL should be proxied according to the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables. Uses a global pool of agents for up to 8 combinations of options (for example, proxied https URLs will share an agent).**
[](https://www.npmjs.org/package/auto-http-agent)
[](https://www.npmjs.org/package/auto-http-agent)

[](https://standardjs.com)
## Usage
```js
const autoAgent = require('auto-http-agent')
const url = 'http://example.com'
const agent = autoAgent(url)
// Pass to your module of choice
request(url, { agent })
```
## API
### `autoAgent(url[, options])`
The `url` argument is required and must either be a string or a [WHATWG `URL`](https://nodejs.org/api/url.html) instance, with an HTTP or HTTPS protocol.
Options:
- `keepAlive` (boolean): reuse connections between requests, default `false`.
Returns an agent or `null` if the default agent can be used (i.e. `http.globalAgent` or `https.globalAgent`). Has a fast path for the common case of not having any configured proxy. The `autoAgent` module should behave the same as good old [`request`](https://github.com/request/request) and other software. It respects the following environment variables.
#### `HTTP_PROXY`
A proxy URL to use for HTTP requests, e.g. `http://localhost:3000`. The proxy itself can be either HTTP or HTTPS.
#### `HTTPS_PROXY`
A proxy URL to use for HTTPS requests. The proxy itself can be either HTTP or HTTPS.
#### `NO_PROXY`
A comma-separated list of hosts (including subdomains) that should not be proxied. Supported forms:
- `hostname:port`
- `hostname` or `.hostname` or `*.hostname`
- `*` to disable proxying for all URLs
## Install
With [npm](https://npmjs.org) do:
```
npm install auto-http-agent
```
## License
[MIT](LICENSE) © Vincent Weevers