Skip to content

Commit d2c5862

Browse files
Merge pull request #350 from jugglingthebits/master
Fix respecting a system or user configured proxy.
2 parents 656adf3 + f0b4441 commit d2c5862

File tree

6 files changed

+108
-10
lines changed

6 files changed

+108
-10
lines changed

gulpfile.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ const del = require('del');
99
const gulp = require('gulp');
1010
const tslint = require('gulp-tslint');
1111
const vsce = require('vsce');
12-
const omnisharpDownload = require('./out/omnisharpDownload');
12+
//const omnisharpDownload = require('./out/omnisharpDownload');
1313

1414
gulp.task('omnisharp:clean', () => {
1515
return del('.omnisharp');
1616
});
1717

18-
gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => {
19-
return omnisharpDownload.downloadOmnisharp();
20-
});
18+
//TODO: decouple omnisharpDownload (specifically proxy.ts) from vscode
19+
// gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => {
20+
// return omnisharpDownload.downloadOmnisharp();
21+
// });
2122

2223
const allTypeScript = [
2324
'src/**/*.ts',
@@ -45,7 +46,7 @@ gulp.task('tslint', () => {
4546
}))
4647
});
4748

48-
gulp.task('omnisharp', ['omnisharp:fetch']);
49+
// gulp.task('omnisharp', ['omnisharp:fetch']);
4950

5051
gulp.task('package', () => {
5152
vsce(['', '', 'package']);

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
"decompress": "^3.0.0",
2626
"del": "^2.0.2",
2727
"fs-extra-promise": "^0.3.1",
28+
"http-proxy-agent": "^1.0.0",
29+
"https-proxy-agent": "^1.0.0",
30+
"open": "*",
2831
"semver": "*",
29-
"vscode-debugprotocol": "^1.6.1",
30-
"vscode-extension-telemetry": "0.0.4",
3132
"tmp": "0.0.28",
32-
"open": "*"
33+
"vscode-debugprotocol": "^1.6.1",
34+
"vscode-extension-telemetry": "0.0.4"
3335
},
3436
"devDependencies": {
3537
"gulp": "^3.9.1",
@@ -364,4 +366,4 @@
364366
}
365367
]
366368
}
367-
}
369+
}

src/omnisharpDownload.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as stream from 'stream';
1212
import * as tmp from 'tmp';
1313
import {parse} from 'url';
1414
import {SupportedPlatform, getSupportedPlatform} from './utils';
15+
import {getProxyAgent} from './proxy';
1516

1617
const Decompress = require('decompress');
1718

@@ -48,10 +49,14 @@ function getOmnisharpAssetName(): string {
4849

4950
function download(urlString: string): Promise<stream.Readable> {
5051
let url = parse(urlString);
52+
53+
const agent = getProxyAgent(url);
54+
5155
let options: https.RequestOptions = {
5256
host: url.host,
5357
path: url.path,
54-
}
58+
agent: agent
59+
};
5560

5661
return new Promise<stream.Readable>((resolve, reject) => {
5762
return https.get(options, res => {

src/proxy.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { Url, parse as parseUrl } from 'url';
9+
import HttpProxyAgent = require('http-proxy-agent');
10+
import HttpsProxyAgent = require('https-proxy-agent');
11+
import {workspace} from 'vscode';
12+
13+
function getSystemProxyURL(requestURL: Url): string {
14+
if (requestURL.protocol === 'http:') {
15+
return process.env.HTTP_PROXY || process.env.http_proxy || null;
16+
} else if (requestURL.protocol === 'https:') {
17+
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null;
18+
}
19+
20+
return null;
21+
}
22+
23+
export function getProxyAgent(requestURL: Url): any {
24+
const vsConfigProxyUrl = workspace.getConfiguration().get<string>('http.proxy');
25+
const proxyURL = vsConfigProxyUrl || getSystemProxyURL(requestURL);
26+
27+
if (!proxyURL) {
28+
return null;
29+
}
30+
31+
const proxyEndpoint = parseUrl(proxyURL);
32+
33+
if (!/^https?:$/.test(proxyEndpoint.protocol)) {
34+
return null;
35+
}
36+
37+
const strictSSL = workspace.getConfiguration().get('http.proxyStrictSSL', true);
38+
const opts = {
39+
host: proxyEndpoint.hostname,
40+
port: Number(proxyEndpoint.port),
41+
auth: proxyEndpoint.auth,
42+
rejectUnauthorized: strictSSL
43+
};
44+
45+
return requestURL.protocol === 'http:' ? new HttpProxyAgent(opts) : new HttpsProxyAgent(opts);
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'http-proxy-agent' {
7+
8+
interface IHttpProxyAgentOptions {
9+
host: string;
10+
port: number;
11+
auth?: string;
12+
}
13+
14+
class HttpProxyAgent {
15+
constructor(proxy: string);
16+
constructor(opts: IHttpProxyAgentOptions);
17+
}
18+
19+
export = HttpProxyAgent;
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'https-proxy-agent' {
7+
8+
import * as tls from 'tls';
9+
10+
interface IHttpsProxyAgentOptions extends tls.ConnectionOptions {
11+
host: string;
12+
port: number;
13+
auth?: string;
14+
secureProxy?: boolean;
15+
secureEndpoint?: boolean;
16+
}
17+
18+
class HttpsProxyAgent {
19+
constructor(proxy: string);
20+
constructor(opts: IHttpsProxyAgentOptions);
21+
}
22+
23+
export = HttpsProxyAgent;
24+
}

0 commit comments

Comments
 (0)