forked from cloudflare/node-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
39 lines (31 loc) · 992 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
'use strict';
const shouldProxy = require('should-proxy');
const HttpsProxyAgent = require('https-proxy-agent');
/**
* proxyAgent returns an HTTPS agent to use to access the base URL.
*
* @private
* @param {string} httpsProxy - HTTPS Proxy URL
* @param {string} noProxy - URLs that should be excluded from proxying
* @param {string} base - The client base URL
* @returns {https.Agent|null} - The HTTPS agent, if required to access the base URL.
*/
const proxyAgent = function proxyAgent(httpsProxy, noProxy, base) {
if (!httpsProxy) {
return null;
}
noProxy = noProxy || '';
const ok = shouldProxy(base, {
no_proxy: noProxy, // eslint-disable-line camelcase
});
if (!ok) {
return null;
}
return new HttpsProxyAgent(httpsProxy);
};
module.exports.proxyAgent = proxyAgent;