Gathering detailed insights and metrics for proxy-http-agent
Gathering detailed insights and metrics for proxy-http-agent
Gathering detailed insights and metrics for proxy-http-agent
Gathering detailed insights and metrics for 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 proxy-http-agent
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
4 Commits
3 Forks
2 Watching
1 Branches
3 Contributors
Updated on 01 Nov 2023
TypeScript (99.57%)
JavaScript (0.43%)
Cumulative downloads
Total Downloads
Last day
104.3%
237
Compared to previous day
Last week
44.4%
937
Compared to previous week
Last month
-9.9%
3,340
Compared to previous month
Last year
91.8%
29,949
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.
Reason
no binaries found in the repo
Reason
3 existing vulnerabilities detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More