feat(bindings): Use HTTPS proxy when provided as environment variable

This commit is contained in:
Erwan Bousse
2022-12-09 16:01:02 +01:00
committed by GitHub
parent 57e09c07dc
commit 1ef645d285
2 changed files with 11 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
const { Agent } = require('https');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { DownloaderHelper } = require('node-downloader-helper');
const { version } = require("./package.json");
const { platform, arch } = process
@@ -23,13 +23,16 @@ function download_lib(libname) {
console.info(`Downloading lib ${libname} from ${url}`);
const dl = new DownloaderHelper(url, __dirname, {
override: true,
httpsRequestOptions: {
// Disable keepalive to prevent the process hanging open.
// https://github.com/matrix-org/matrix-rust-sdk/issues/1160
agent: new Agent({ keepAlive: false }),
},
});
const proxy = process.env.https_proxy ?? process.env.HTTPS_PROXY;
if (proxy) {
const proxyAgent = new HttpsProxyAgent(proxy);
dl.updateOptions({
httpsRequestOptions: { agent: proxyAgent },
});
}
dl.on('end', () => console.info('Download Completed'));
dl.on('error', (err) => console.info('Download Failed', err));
dl.on('progress', stats => {

View File

@@ -29,6 +29,7 @@
"doc": "typedoc --tsconfig ."
},
"dependencies": {
"node-downloader-helper": "^2.1.1"
"https-proxy-agent": "^5.0.1",
"node-downloader-helper": "^2.1.5"
}
}