Skip to content

Commit

Permalink
fix proxy implementation for https over http
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarrishav authored Apr 12, 2022
1 parent 46316d2 commit ac1d5cd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions installers/npm/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const cTable = require("console.table");
const libc = require("detect-libc");
const { join } = require("path");
const { configureProxy } = require("axios-proxy-builder");
const tunnel = require('tunnel');

const error = (msg) => {
console.error(msg);
Expand Down Expand Up @@ -111,8 +112,23 @@ const run = () => {

const install = () => {
const binary = getBinary();
const proxy = configureProxy(binary.url);
binary.install(proxy);
const binaryUrlProtocol = new URL(binary.url).protocol;
const fetchOptions = configureProxy(binary.url);

// axios proxy implementation for https over http doesn't work. hence, this implementation
if (binaryUrlProtocol === 'https:' && (fetchOptions && fetchOptions.proxy && fetchOptions.proxy.protocol === 'http:')) {
const agent = tunnel.httpsOverHttp({
proxy: {
host: fetchOptions.proxy.hostname
port: fetchOptions.proxy.port
}
});

fetchOptions.proxy = false;
fetchOptions.httpsAgent = agent;
}

binary.install(fetchOptions);

// use setTimeout so the message prints after the install happens.
setTimeout(() => {
Expand Down

0 comments on commit ac1d5cd

Please sign in to comment.