The "Got" library failed to download electron behind local proxy
lucascloarec opened this issue · 1 comments
Hi,
I use winfoom (https://github.com/ecovaci/winfoom) as a local proxy to connect my apps to our corporate proxy and I encounter the following error:
npm ERR! code 1
npm ERR! path C:\...\workspace\pki-gnokey\node_modules\electron
npm ERR! command failed
npm ERR! command C:\Program Files\Git\bin\bash.exe -c node install.js
npm ERR! RequestError: write EPROTO DC7D0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
npm ERR!
npm ERR! at ClientRequest.<anonymous> (C:\...\workspace\pki-gnokey\node_modules\got\dist\source\core\index.js:970:111)
npm ERR! at Object.onceWrapper (node:events:628:26)
npm ERR! at ClientRequest.emit (node:events:525:35)
npm ERR! at ClientRequest.emit (node:domain:489:12)
npm ERR! at origin.emit (C:\...\workspace\pki-gnokey\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
npm ERR! at TLSSocket.socketErrorListener (node:_http_client:502:9)
npm ERR! at TLSSocket.emit (node:events:525:35)
npm ERR! at TLSSocket.emit (node:domain:489:12)
npm ERR! at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR! at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR! at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
I have these environment variables:
ELECTRON_GET_USE_PROXY=true
GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:3128
http_proxy=http://127.0.0.1:3128
https_proxy=http://127.0.0.1:3128
I have the impression that the SSL/TLS negotiation does not succeed because "got" forces the use of a too old version which is not compatible with my local proxy.
Also I don't encounter the problem when I use my own implementation of the Downloader interface, with axios instead of "got" :
import {Downloader} from "@electron/get/dist/esm/Downloader";
import * as fs from 'fs';
import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
import * as Stream from "stream";
export class CustomDownloader implements Downloader<AxiosRequestConfig> {
async download(url: string, path: string, options: AxiosRequestConfig = {}): Promise<void> {
const writer = fs.createWriteStream(path)
const response: AxiosResponse<Stream> = await axios.get(
url, {
...options,
responseType: 'stream'
}
)
response.data.pipe(writer)
return new Promise((resolve, reject) => {
writer.on('finish', resolve)
writer.on('error', reject)
})
}
}
import {download} from "@electron/get";
import {CustomDownloader} from "./custom-downloader";
const version = "24.0.0";
(async () => {
const zipFilePath = await download(
version,
{
downloader: new CustomDownloader(), // this script fails if this line is removed
}
);
console.debug(zipFilePath)
console.log("OK")
})()
My implementation of the Downloader interface is more basic than the current implementation that uses "got", it doesn't allow customization with the progress bar (is that really useful?), but I still suggest add it and allow to choose it (for example with the environment variable ELECTRON_GET_USE_AXIOS=true), or simply replace the current implementation.
me