From b8f01e4dffd3e1208e08ded719f09c365416f9b1 Mon Sep 17 00:00:00 2001 From: Stephan Oehlert Date: Thu, 19 May 2016 16:39:26 +0200 Subject: [PATCH 1/6] Fix respecting a system or user configured proxy. Add libraries http-proxy-agent and https-proxy-agent just like vscode itself does and then use that to request omnisharp binaries. Most code is taken from vscode and adapted. --- package.json | 14 +++--- src/omnisharpDownload.ts | 7 ++- src/proxy.ts | 46 +++++++++++++++++++ .../http-proxy-agent/http-proxy-agent.d.ts | 20 ++++++++ .../https-proxy-agent/https-proxy-agent.d.ts | 24 ++++++++++ 5 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/proxy.ts create mode 100644 src/typings/http-proxy-agent/http-proxy-agent.d.ts create mode 100644 src/typings/https-proxy-agent/https-proxy-agent.d.ts diff --git a/package.json b/package.json index 3bf121fce1..4bd6086963 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", @@ -139,9 +141,9 @@ "csharp" ] }, - "runtime": "node", + "runtime": "", "runtimeArgs": [], - "program": "./out/coreclr-debug/proxy.js", + "program": "./coreclr-debug/debugAdapters/OpenDebugAD7.exe", "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", "configurationAttributes": { "launch": { @@ -364,4 +366,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; +} From 37c9053d1c9a70a3b2334095b3eedc19fb1e4887 Mon Sep 17 00:00:00 2001 From: Stephan Oehlert Date: Thu, 19 May 2016 19:40:24 +0200 Subject: [PATCH 2/6] Revert unintended change to package.json. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4bd6086963..c32de77364 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ }, "runtime": "", "runtimeArgs": [], - "program": "./coreclr-debug/debugAdapters/OpenDebugAD7.exe", + "program": "./out/coreclr-debug/proxy.js", "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", "configurationAttributes": { "launch": { From 656adf3486f379bc40d684298fbff009562ec6ce Mon Sep 17 00:00:00 2001 From: Gregg Miskelly Date: Thu, 19 May 2016 12:40:29 -0700 Subject: [PATCH 3/6] Update .NET Core Link --- debugger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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` From a6f0559434af0471b153be03281b3328483f156f Mon Sep 17 00:00:00 2001 From: Stephan Oehlert Date: Sat, 21 May 2016 13:51:15 +0200 Subject: [PATCH 4/6] Comment out the omnisharp:fetch gulp task as it doesn't work when download tries to get proxy info from the user's config. --- gulpfile.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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']); From f0b44417c2e87a80fbdc5762a602df02e6cdb67e Mon Sep 17 00:00:00 2001 From: Stephan Oehlert Date: Mon, 23 May 2016 20:24:47 +0200 Subject: [PATCH 5/6] Revert empty runtime setting change. Weird that this was changed at all. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c32de77364..c743ee7946 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "csharp" ] }, - "runtime": "", + "runtime": "node", "runtimeArgs": [], "program": "./out/coreclr-debug/proxy.js", "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", From 2ff231505fc62e78b9f40eb58bb1f164ddf82a8a Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 23 May 2016 11:39:39 -0700 Subject: [PATCH 6/6] Update version to 1.0.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c743ee7946..6a270cbeea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "csharp", "publisher": "ms-vscode", - "version": "1.0.11", + "version": "1.0.12", "description": "C# for Visual Studio Code (powered by OmniSharp).", "displayName": "C#", "author": "Microsoft Corporation",