Skip to content

Commit

Permalink
feat(bindings): Use HTTPS proxy when provided as environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ebousse authored Dec 9, 2022
1 parent 57e09c0 commit 1ef645d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions bindings/matrix-sdk-crypto-nodejs/download-lib.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 => {
Expand Down
3 changes: 2 additions & 1 deletion bindings/matrix-sdk-crypto-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 1ef645d

Please sign in to comment.