diff --git a/debugger.md b/debugger.md index 92e3d38dde..d548941c09 100644 --- a/debugger.md +++ b/debugger.md @@ -19,7 +19,7 @@ If you are not sure what version you have, you can see your version of VS Code: * **Windows / Linux:** Help->About ##### 2: Install .NET command line tools -Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: http://dotnet.github.io/getting-started +Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: https://www.microsoft.com/net/core **OSX:** .NET Core requires openSSL to work. Don't forget this! Execute: `brew install openssl` diff --git a/gulpfile.js b/gulpfile.js index 7ebcf0e682..9522da46b9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,15 +9,16 @@ const del = require('del'); const gulp = require('gulp'); const tslint = require('gulp-tslint'); const vsce = require('vsce'); -const omnisharpDownload = require('./out/omnisharpDownload'); +//const omnisharpDownload = require('./out/omnisharpDownload'); gulp.task('omnisharp:clean', () => { return del('.omnisharp'); }); -gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => { - return omnisharpDownload.downloadOmnisharp(); -}); +//TODO: decouple omnisharpDownload (specifically proxy.ts) from vscode +// gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => { +// return omnisharpDownload.downloadOmnisharp(); +// }); const allTypeScript = [ 'src/**/*.ts', @@ -45,7 +46,7 @@ gulp.task('tslint', () => { })) }); -gulp.task('omnisharp', ['omnisharp:fetch']); +// gulp.task('omnisharp', ['omnisharp:fetch']); gulp.task('package', () => { vsce(['', '', 'package']); diff --git a/package.json b/package.json index 5f1d3c5dbd..48d3a70bef 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,13 @@ "decompress": "^3.0.0", "del": "^2.0.2", "fs-extra-promise": "^0.3.1", + "http-proxy-agent": "^1.0.0", + "https-proxy-agent": "^1.0.0", + "open": "*", "semver": "*", - "vscode-debugprotocol": "^1.6.1", - "vscode-extension-telemetry": "0.0.4", "tmp": "0.0.28", - "open": "*" + "vscode-debugprotocol": "^1.6.1", + "vscode-extension-telemetry": "0.0.4" }, "devDependencies": { "gulp": "^3.9.1", @@ -373,4 +375,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/omnisharpDownload.ts b/src/omnisharpDownload.ts index 0e8a889207..4b42cf4a58 100644 --- a/src/omnisharpDownload.ts +++ b/src/omnisharpDownload.ts @@ -12,6 +12,7 @@ import * as stream from 'stream'; import * as tmp from 'tmp'; import {parse} from 'url'; import {SupportedPlatform, getSupportedPlatform} from './utils'; +import {getProxyAgent} from './proxy'; const Decompress = require('decompress'); @@ -48,10 +49,14 @@ function getOmnisharpAssetName(): string { function download(urlString: string): Promise { let url = parse(urlString); + + const agent = getProxyAgent(url); + let options: https.RequestOptions = { host: url.host, path: url.path, - } + agent: agent + }; return new Promise((resolve, reject) => { return https.get(options, res => { diff --git a/src/proxy.ts b/src/proxy.ts new file mode 100644 index 0000000000..1eaa96197a --- /dev/null +++ b/src/proxy.ts @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { Url, parse as parseUrl } from 'url'; +import HttpProxyAgent = require('http-proxy-agent'); +import HttpsProxyAgent = require('https-proxy-agent'); +import {workspace} from 'vscode'; + +function getSystemProxyURL(requestURL: Url): string { + if (requestURL.protocol === 'http:') { + return process.env.HTTP_PROXY || process.env.http_proxy || null; + } else if (requestURL.protocol === 'https:') { + return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null; + } + + return null; +} + +export function getProxyAgent(requestURL: Url): any { + const vsConfigProxyUrl = workspace.getConfiguration().get('http.proxy'); + const proxyURL = vsConfigProxyUrl || getSystemProxyURL(requestURL); + + if (!proxyURL) { + return null; + } + + const proxyEndpoint = parseUrl(proxyURL); + + if (!/^https?:$/.test(proxyEndpoint.protocol)) { + return null; + } + + const strictSSL = workspace.getConfiguration().get('http.proxyStrictSSL', true); + const opts = { + host: proxyEndpoint.hostname, + port: Number(proxyEndpoint.port), + auth: proxyEndpoint.auth, + rejectUnauthorized: strictSSL + }; + + return requestURL.protocol === 'http:' ? new HttpProxyAgent(opts) : new HttpsProxyAgent(opts); +} diff --git a/src/typings/http-proxy-agent/http-proxy-agent.d.ts b/src/typings/http-proxy-agent/http-proxy-agent.d.ts new file mode 100644 index 0000000000..d73d3d14dc --- /dev/null +++ b/src/typings/http-proxy-agent/http-proxy-agent.d.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'http-proxy-agent' { + + interface IHttpProxyAgentOptions { + host: string; + port: number; + auth?: string; + } + + class HttpProxyAgent { + constructor(proxy: string); + constructor(opts: IHttpProxyAgentOptions); + } + + export = HttpProxyAgent; +} diff --git a/src/typings/https-proxy-agent/https-proxy-agent.d.ts b/src/typings/https-proxy-agent/https-proxy-agent.d.ts new file mode 100644 index 0000000000..748e5cf365 --- /dev/null +++ b/src/typings/https-proxy-agent/https-proxy-agent.d.ts @@ -0,0 +1,24 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'https-proxy-agent' { + + import * as tls from 'tls'; + + interface IHttpsProxyAgentOptions extends tls.ConnectionOptions { + host: string; + port: number; + auth?: string; + secureProxy?: boolean; + secureEndpoint?: boolean; + } + + class HttpsProxyAgent { + constructor(proxy: string); + constructor(opts: IHttpsProxyAgentOptions); + } + + export = HttpsProxyAgent; +}