From 1ef645d285324445ae103bca5c09f8dc103e643e Mon Sep 17 00:00:00 2001 From: Erwan Bousse Date: Fri, 9 Dec 2022 16:01:02 +0100 Subject: [PATCH] feat(bindings): Use HTTPS proxy when provided as environment variable --- bindings/matrix-sdk-crypto-nodejs/download-lib.js | 15 +++++++++------ bindings/matrix-sdk-crypto-nodejs/package.json | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bindings/matrix-sdk-crypto-nodejs/download-lib.js b/bindings/matrix-sdk-crypto-nodejs/download-lib.js index d0aec7d78..6e360db13 100644 --- a/bindings/matrix-sdk-crypto-nodejs/download-lib.js +++ b/bindings/matrix-sdk-crypto-nodejs/download-lib.js @@ -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 => { diff --git a/bindings/matrix-sdk-crypto-nodejs/package.json b/bindings/matrix-sdk-crypto-nodejs/package.json index c4c1e875a..d858158e2 100644 --- a/bindings/matrix-sdk-crypto-nodejs/package.json +++ b/bindings/matrix-sdk-crypto-nodejs/package.json @@ -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" } }