https-proxy-agent
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
agent-base | 7.1.1 | 30.52 kB | MIT | prod | |
debug | 4.3.4 | 12.94 kB | MIT | prod |
The "https-proxy-agent" is an npm package that provides an "http.Agent" implementation to connect through a specified HTTP or HTTPS proxy server. This package is compatible and works welter with the built-in "https" module. Its core advantage is the implementation of the CONNECT HTTP method, which allows setting up of a direct TCP connection to the destination server via an intermediary "proxy" server. The method's versatility makes it compatible with other protocols using similar methods to establish connections over proxies, which includes WebSockets.
Using "https-proxy-agent" is fairly straightforward. Below is an example of how you can use it with the "https" module:
import * as https from 'https';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent('http://168.63.76.32:3128');
https.get('https://example.com', { agent }, (res) => {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
And here's an example of using it for WebSocket connections:
import WebSocket from 'ws';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent('http://168.63.76.32:3128');
const socket = new WebSocket('ws://echo.websocket.org', { agent });
socket.on('open', function () {
console.log('"open" event!');
socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});
For more comprehensive information on the "https-proxy-agent", refer to the package's documentation available on its GitHub repository. The URL for the GitHub repository is https://github.com/TooTallNate/proxy-agents. Details about the "HttpsProxyAgent" class, its constructor, accepted arguments, and additional properties of the "options" argument can be found in the API section of the readme file in the repository. Keep up with the repository for any updates or changes in functionality.