Gathering detailed insights and metrics for @audc/proxy-http-agent
Gathering detailed insights and metrics for @audc/proxy-http-agent
Gathering detailed insights and metrics for @audc/proxy-http-agent
Gathering detailed insights and metrics for @audc/proxy-http-agent
A factory to create http proxy agent! Based on the tunnel module! To use a proxy through modules like http and https or node-fetch! It support https => (http, https) and http => (http, https). (proxy => server) ! Either the proxy is http and either it will go as a tunnel for http! Or a tunnel for https through the CONNECT method! Or the proxy will be https! And direct forwarding will go!
npm install @audc/proxy-http-agent
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
7 Commits
1 Branches
Updated on 22 Nov 2021
TypeScript (99.58%)
JavaScript (0.42%)
Cumulative downloads
Total Downloads
Last day
527.3%
69
Compared to previous day
Last week
170.7%
360
Compared to previous week
Last month
66%
1,235
Compared to previous month
Last year
-5.8%
7,928
Compared to previous year
2
A factory to create http proxy agent! Based on the tunnel module! To use a proxy through modules like http and https or node-fetch!
It support https => (http, https) and http => (http, https). (proxy => server) ! Either the proxy is http and either it will go as a tunnel for http! Or a tunnel for https through the CONNECT method! Or the proxy will be https! And direct forwarding will go!
1npm install proxy-http-agent --save
The name start with proxy and make the accent on https agent to highlight that it's https.Agent
1let agent = getProxyHttpAgent(options);
1const { getProxyHttpAgent } = require('proxy-http-agent'); 2 3let proxyUrl = 4 process.env.HTTP_PROXY || 5 process.env.http_proxy || 6 `http://localhost:${proxyPort}`; 7 8let agent = getProxyHttpAgent({ 9 proxy: proxyUrl, 10 rejectUnauthorized: false 11});
Also the module is build by typescript! It support typescript too out of the box!
1import { getProxyHttpAgent } = from 'proxy-http-agent'; 2import https from 'https'; 3 4let proxyUrl = 5 process.env.HTTP_PROXY || 6 process.env.http_proxy || 7 `http://localhost:${proxyPort}`; 8 9let agent: https.Agent = getProxyHttpAgent({ 10 proxy: proxyUrl, 11 rejectUnauthorized: false 12});
In the core the options are the direct options of http.Agent
and https.Agent
and tunnel module factories options
Check the node-tunnel repo here
https://github.com/koichik/node-tunnel/
Plus our extra options:
(Obligatory)
1interface IProxyOptions { 2 host: string; 3 port: number; 4 protocol?: 'http:' | 'https:'; 5 localAddress?: string; 6 proxyAuth?: string; 7 headers?: { [key: string]: any }; 8}
1interface IHttpsProxyOptions extends IProxyOptions { 2 ca?: Buffer[]; 3 servername?: string; 4 key?: Buffer; 5 cert?: Buffer; 6}
string: the proxy url
(optional) default: 'https:'
For typescript you can also get directly https.Agent type from this module as follow
1import { getProxyHttpAgent, HttpsAgent, HttpAgent } = from 'proxy-http-agent'; 2 3let proxyUrl = 4 process.env.HTTP_PROXY || 5 process.env.http_proxy || 6 `http://localhost:${proxyPort}`; 7 8let agent: HttpsAgent = getProxyHttpAgent({ 9 proxy: proxyUrl, 10 rejectUnauthorized: false 11});
We do expose and export it too.
From the test files here some nice examples
(default is https)
1let proxyUrl =
2 process.env.HTTP_PROXY ||
3 process.env.http_proxy ||
4 `http://localhost:${proxyPort}`;
5
6let agent = getProxyHttpAgent({
7 proxy: proxyUrl, // proxy as url string! We can use an object (as tunnel module require too)
8 rejectUnauthorized: false
9});
10
11try {
12 console.log(('fetch :::: :: :: :: :'))
13 const response = await fetch(`https://localhost:${localApiHttpsServerPort}`, {
14 method: 'GET',
15 agent
16 });
17
18 console.log('"response !!!!!!!!!!!!"')
19
20 if (response.status === 200) {
21 const data = await response.json();
22
23 console.log(data)
24
25 if (data) {
26 expect(data.host).toEqual(`localhost:${localApiHttpsServerPort}`);
27 } else {
28 fail(new Error('No data from local server!'));
29 }
30 }
31} catch(err) {
32 fail(err);
33}
1let proxyUrl = 2 process.env.HTTP_PROXY || 3 process.env.http_proxy || 4 `http://localhost:${proxyPort}`; 5 6let agent = getProxyHttpAgent({ 7 proxy: proxyUrl 8}); 9 10const opts: any = url.parse(`https://api.binance.com/api/v3/ping`); 11delete opts.port; 12opts.agent = agent; 13 14let req = https.get(opts, function(res) { 15 let data: any = ''; 16 res.setEncoding('utf8'); 17 res.on('data', function(b) { 18 console.log('::::::::::::::::::::::::::::::::::::://///>') 19 console.log('DATA ::::') 20 data += b; 21 }); 22 res.on('end', function() { 23 console.log('RESPONSE END :::::::::::////>') 24 data = JSON.parse(data); 25 26 console.log(data) 27 28 expect(data).toEqual({}); 29 done(); 30 }); 31}); 32req.once('error', done);
1let proxyUrl =
2 process.env.HTTP_PROXY ||
3 process.env.http_proxy ||
4 `http://localhost:${proxyPort}`;
5
6let agent = getProxyHttpAgent({
7 proxy: proxyUrl,
8 endServerProtocol: 'http:' // <<==== here (we precise that we need an agent to communicate with an end server that work with http)
9});
10
11try {
12 console.log("Fetch ::::>")
13 const response = await fetch(`http://localhost:${localApiServerPort}`, {
14 method: 'GET',
15 agent
16 });
17
18 console.log('response :::::::::////>')
19
20 if (response.status === 200) {
21 const data = await response.json();
22
23 if (data) {
24 expect(data.host).toEqual(`localhost:${localApiServerPort}`);
25 } else {
26 fail(new Error('No data from local server!'));
27 }
28 }
29} catch(err) {
30 fail(err);
31}
No vulnerabilities found.
No security vulnerabilities found.