var/const updates

This commit is contained in:
Steve-Mcl 2024-03-17 12:37:42 +00:00
parent f61971bc23
commit c368bfea3f
2 changed files with 7 additions and 14 deletions

View File

@ -515,20 +515,13 @@ in your Node-RED user directory (${RED.settings.userDir}).
opts.headers['user-agent'] = 'Mozilla/5.0 (Node-RED)'; opts.headers['user-agent'] = 'Mozilla/5.0 (Node-RED)';
} }
if (proxyUrl) { if (proxyUrl) {
var match = proxyUrl.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i); const match = proxyUrl.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
if (match) { if (match) {
const proxyURL = parseUrl(proxyUrl) const proxyURL = parseUrl(proxyUrl)
//set username/password to null to stop empty creds header //set username/password to null to stop empty creds header
/** @type {HttpProxyAgentOptions} */ /** @type {import('hpagent').HttpProxyAgentOptions} */
let proxyOptions = { let proxyOptions = {
proxy: proxyUrl, proxy: proxyUrl,
// proxy: {
// protocol: proxyURL.protocol,
// hostname: proxyURL.hostname,
// port: proxyURL.port,
// username: null,
// password: null
// },
scheduling: 'lifo', scheduling: 'lifo',
maxFreeSockets: 256, maxFreeSockets: 256,
maxSockets: 256, maxSockets: 256,
@ -554,7 +547,7 @@ in your Node-RED user directory (${RED.settings.userDir}).
}; };
} else { } else {
node.warn("Bad proxy url: "+ proxyUrl); node.warn("Bad proxy url: " + proxyUrl);
} }
} }
if (tlsNode) { if (tlsNode) {

View File

@ -70,11 +70,11 @@ function testProxyUrl(env, expected, input, options) {
// the call of this function and the use of it below. // the call of this function and the use of it below.
env = JSON.parse(JSON.stringify(env)); env = JSON.parse(JSON.stringify(env));
var title = 'getProxyForUrl(' + JSON.stringify(input) + ')' + const title = 'getProxyForUrl(' + JSON.stringify(input) + ')' +
' === ' + JSON.stringify(expected); ' === ' + JSON.stringify(expected);
// Save call stack for later use. // Save call stack for later use.
var stack = {}; const stack = {};
Error.captureStackTrace(stack, testProxyUrl); Error.captureStackTrace(stack, testProxyUrl);
// Only use the last stack frame because that shows where this function is // Only use the last stack frame because that shows where this function is
// called, and that is sufficient for our purpose. No need to flood the logs // called, and that is sufficient for our purpose. No need to flood the logs
@ -82,7 +82,7 @@ function testProxyUrl(env, expected, input, options) {
stack = stack.stack.split('\n', 2)[1]; stack = stack.stack.split('\n', 2)[1];
it(title, function () { it(title, function () {
var actual; let actual;
// runWithEnv(env, function () { // runWithEnv(env, function () {
// actual = getProxyForUrl(input, options); // actual = getProxyForUrl(input, options);
// }); // });
@ -105,7 +105,7 @@ function testProxyUrl(env, expected, input, options) {
}); });
} }
describe('Proxy Helper', function () { describe.only('Proxy Helper', function () {
describe('No proxy variables', function () { describe('No proxy variables', function () {
const env = {}; const env = {};
testProxyUrl(env, '', 'http://example.com'); testProxyUrl(env, '', 'http://example.com');