diff --git a/package.json b/package.json index a2941924..6d314640 100644 --- a/package.json +++ b/package.json @@ -206,6 +206,11 @@ ], "default": "stable" }, + "language-1c-bsl.languageServerDownloadProxy": { + "description": "Proxy URL for downloading BSL LS binaries", + "type": "string", + "default": "" + }, "language-1c-bsl.languageServerExternalJar": { "description": "Use external bsl-language-server.jar", "type": "boolean", @@ -355,6 +360,7 @@ "request": "^2.88.0", "request-progress": "^3.0.0", "request-promise-native": "^1.0.8", + "https-proxy-agent": "^5.0.0", "semver": "^7.1.1", "vsce": "^1.71.0", "vscode-languageclient": "^6.1.0", diff --git a/src/util/downloadUtils.ts b/src/util/downloadUtils.ts index 33d47de3..e1198f61 100644 --- a/src/util/downloadUtils.ts +++ b/src/util/downloadUtils.ts @@ -33,10 +33,12 @@ const requestProgress = require("request-progress"); export function download( srcUrl: string, destPath: fs.PathLike, - progress: (percent: number) => void + progress: (percent: number) => void, + proxySettings: string = null ): Promise { return new Promise((resolve, reject) => { - requestProgress(request.get(srcUrl)) + var proxiedRq = request.defaults({proxy: proxySettings}) + requestProgress(proxiedRq.get(srcUrl)) .on("progress", state => progress(state.percent)) .on("complete", () => resolve()) .on("error", err => reject(err)) diff --git a/src/util/serverDownloader.ts b/src/util/serverDownloader.ts index 928b3f5c..bf2d63ad 100644 --- a/src/util/serverDownloader.ts +++ b/src/util/serverDownloader.ts @@ -36,6 +36,8 @@ import BSLLanguageServerDownloadChannel from "./bsllsDownloadChannel"; import { download } from "./downloadUtils"; import { IGitHubReleasesAPIResponse } from "./githubApi"; import { IStatus } from "./status"; +import * as vscode from "vscode"; +import { LANGUAGE_1C_BSL_CONFIG } from "../const"; const extractZip = promisify(extractZipWithCallback); @@ -56,6 +58,7 @@ export class ServerDownloader { private readonly assetName: string; private readonly installDir: string; private readonly token: string; + private readonly proxySettings: string; constructor( displayName: string, @@ -71,6 +74,12 @@ export class ServerDownloader { this.installDir = installDir; this.assetName = assetName; this.token = token; + + const configuration = vscode.workspace.getConfiguration(LANGUAGE_1C_BSL_CONFIG); + var proxyFromConfig:string = configuration.get("languageServerDownloadProxy"); + if(proxyFromConfig) { + this.proxySettings = proxyFromConfig; + } } public async downloadServerIfNeeded(status: IStatus, channel: BSLLanguageServerDownloadChannel): Promise { @@ -150,7 +159,10 @@ export class ServerDownloader { const rawJsonReleases = await requestPromise.get( `https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases`, - { headers } + { + headers, + proxy: this.proxySettings || null + } ); const releases = JSON.parse(rawJsonReleases, jsonDateParser) as IGitHubReleasesAPIResponse[]; @@ -172,7 +184,10 @@ export class ServerDownloader { const rawJson = await requestPromise.get( `https://api.github.com/repos/${this.githubOrganization}/${this.githubProjectName}/releases/${id}`, - { headers } + { + headers, + proxy: this.proxySettings || null + } ); return JSON.parse(rawJson) as IGitHubReleasesAPIResponse; } @@ -211,9 +226,10 @@ export class ServerDownloader { status.update(`Downloading ${this.displayName} ${version}...`); await download(downloadUrl, downloadDest, percent => { status.update( - `Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %` - ); - }); + `Downloading ${this.displayName} ${version} :: ${(percent * 100).toFixed(2)} %`); + }, + this.proxySettings + ); status.update(`Unpacking ${this.displayName} ${version}...`); await extractZip(downloadDest, { dir: path.join(this.installDir, version) });