Skip to content

Commit eaa5bcf

Browse files
committed
bring proxy stuff together
add http.proxyStrictSSL option fixes microsoft#155
1 parent 9b6bff1 commit eaa5bcf

6 files changed

Lines changed: 102 additions & 54 deletions

File tree

src/typings/https-proxy-agent.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55

66
declare module 'https-proxy-agent' {
77

8+
import * as tls from 'tls';
9+
10+
interface IHttpsProxyAgentOptions extends tls.ConnectionOptions {
11+
host: string;
12+
port: number;
13+
secureProxy?: boolean;
14+
secureEndpoint?: boolean;
15+
}
16+
817
class HttpsProxyAgent {
918
constructor(proxy: string);
19+
constructor(opts: IHttpsProxyAgentOptions);
1020
}
21+
1122
export = HttpsProxyAgent;
1223
}

src/vs/base/node/request.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import http = require('http');
1111
import { Url, parse as parseUrl } from 'url';
1212
import { createWriteStream } from 'fs';
1313
import { assign } from 'vs/base/common/objects';
14-
import HttpProxyAgent = require('http-proxy-agent');
15-
import HttpsProxyAgent = require('https-proxy-agent');
1614

1715
export interface IRequestOptions {
1816
type?: string;
@@ -100,36 +98,4 @@ export function json<T>(opts: IRequestOptions): TPromise<T> {
10098
pair.res.on('end', () => c(JSON.parse(buffer.join(''))));
10199
pair.res.on('error', e);
102100
}));
103-
}
104-
105-
function getSystemProxyURI(requestURL: Url): string {
106-
if (requestURL.protocol === 'http:') {
107-
return process.env.HTTP_PROXY || process.env.http_proxy || null;
108-
} else if (requestURL.protocol === 'https:') {
109-
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null;
110-
}
111-
112-
return null;
113-
}
114-
115-
export function getProxyAgent(rawRequestURL: string, proxyURL: string): any {
116-
let requestURL = parseUrl(rawRequestURL);
117-
let proxyEndpoint = parseUrl(proxyURL);
118-
119-
if (!/^https?:$/.test(proxyEndpoint.protocol)) {
120-
return null;
121-
}
122-
123-
return requestURL.protocol === 'http:' ? new HttpProxyAgent(proxyURL) : new HttpsProxyAgent(proxyURL);
124-
}
125-
126-
export function getSystemProxyAgent(rawRequestURL: string): any {
127-
let requestURL = parseUrl(rawRequestURL);
128-
let proxyURL = getSystemProxyURI(requestURL);
129-
130-
if (!proxyURL) {
131-
return null;
132-
}
133-
134-
return getProxyAgent(rawRequestURL, proxyURL);
135101
}

src/vs/workbench/electron-main/win32/auto-updater.win32.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {ClientRequest} from 'http';
1717
import {mkdirp} from 'vs/base/node/extfs';
1818
import {isString} from 'vs/base/common/types';
1919
import {Promise, TPromise} from 'vs/base/common/winjs.base';
20-
import {IRequestOptions, download, json, getProxyAgent, getSystemProxyAgent} from 'vs/base/node/request';
20+
import {IRequestOptions, download, json } from 'vs/base/node/request';
21+
import { getProxyAgent } from 'vs/workbench/node/proxy';
2122
import {manager as Settings} from 'vs/workbench/electron-main/settings';
2223
import {manager as Lifecycle} from 'vs/workbench/electron-main/lifecycle';
2324

@@ -53,11 +54,11 @@ export class Win32AutoUpdaterImpl extends events.EventEmitter implements IAutoUp
5354

5455
this.emit('checking-for-update');
5556

56-
const httpProxySettings = Settings.getValue('http.proxy');
57-
const getAgent = url => httpProxySettings ? getProxyAgent(url, httpProxySettings) : getSystemProxyAgent(url);
57+
const proxyUrl = Settings.getValue('http.proxy');
58+
const strictSSL = Settings.getValue('http.proxy.strictSSL', true);
59+
const agent = getProxyAgent(this.url, { proxyUrl, strictSSL });
5860

59-
this.currentRequest =
60-
json<IUpdate>({ url: this.url, agent: getAgent(this.url) })
61+
this.currentRequest = json<IUpdate>({ url: this.url, agent })
6162
.then(update => {
6263
if (!update || !update.url || !update.version) {
6364
this.emit('update-not-available');
@@ -73,9 +74,10 @@ export class Win32AutoUpdaterImpl extends events.EventEmitter implements IAutoUp
7374
return TPromise.as(updatePackagePath);
7475
}
7576

76-
let downloadPath = `${updatePackagePath}.tmp`;
77+
const downloadPath = `${updatePackagePath}.tmp`;
78+
const agent = getProxyAgent(update.url, { proxyUrl, strictSSL });
7779

78-
return download(downloadPath, { url: update.url, agent: getAgent(update.url) })
80+
return download(downloadPath, { url: update.url, agent })
7981
.then(() => pfs.rename(downloadPath, updatePackagePath))
8082
.then(() => updatePackagePath);
8183
});

src/vs/workbench/node/proxy.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Url, parse as parseUrl } from 'url';
2+
import HttpProxyAgent = require('http-proxy-agent');
3+
import HttpsProxyAgent = require('https-proxy-agent');
4+
5+
function getAgent(rawRequestURL: string, proxyURL: string, strictSSL: boolean = true): any {
6+
let requestURL = parseUrl(rawRequestURL);
7+
let proxyEndpoint = parseUrl(proxyURL);
8+
9+
if (!/^https?:$/.test(proxyEndpoint.protocol)) {
10+
return null;
11+
}
12+
13+
if (requestURL.protocol === 'http:') {
14+
return new HttpProxyAgent(proxyURL);
15+
}
16+
17+
return new HttpsProxyAgent({
18+
host: proxyEndpoint.host,
19+
port: Number(proxyEndpoint.port),
20+
rejectUnauthorized: strictSSL
21+
});
22+
}
23+
24+
function getSystemProxyURI(requestURL: Url): string {
25+
if (requestURL.protocol === 'http:') {
26+
return process.env.HTTP_PROXY || process.env.http_proxy || null;
27+
} else if (requestURL.protocol === 'https:') {
28+
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null;
29+
}
30+
31+
return null;
32+
}
33+
34+
function getSystemProxyAgent(rawRequestURL: string): any {
35+
let requestURL = parseUrl(rawRequestURL);
36+
let proxyURL = getSystemProxyURI(requestURL);
37+
38+
if (!proxyURL) {
39+
return null;
40+
}
41+
42+
return getAgent(rawRequestURL, proxyURL);
43+
}
44+
45+
export interface IOptions {
46+
proxyUrl?: string;
47+
strictSSL?: boolean;
48+
}
49+
50+
export function getProxyAgent(rawRequestURL: string, options: IOptions = {}): any {
51+
console.log(rawRequestURL, options);
52+
53+
if (!options.proxyUrl) {
54+
return getSystemProxyAgent(rawRequestURL);
55+
}
56+
57+
return getAgent(rawRequestURL, options.proxyUrl, options.strictSSL);
58+
}

src/vs/workbench/parts/extensions/node/extensionsService.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { assign } from 'vs/base/common/objects';
1616
import { extract, buffer } from 'vs/base/node/zip';
1717
import { Promise, TPromise } from 'vs/base/common/winjs.base';
1818
import { IExtensionsService, IExtension, IExtensionManifest, IGalleryInformation } from 'vs/workbench/parts/extensions/common/extensions';
19-
import { download, getProxyAgent, getSystemProxyAgent } from 'vs/base/node/request';
19+
import { download } from 'vs/base/node/request';
20+
import { getProxyAgent } from 'vs/workbench/node/proxy';
2021
import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService';
2122
import { Limiter } from 'vs/base/common/async';
2223
import Event, { Emitter } from 'vs/base/common/event';
@@ -121,18 +122,23 @@ export class ExtensionsService implements IExtensionsService {
121122
const extensionPath = path.join(this.extensionsPath, `${ extension.publisher }.${ extension.name }`);
122123
const manifestPath = path.join(extensionPath, 'package.json');
123124

124-
return UserSettings.getValue(this.contextService, 'http.proxy').then((httpProxySettings) => {
125-
const getAgent = url => httpProxySettings ? getProxyAgent(url, httpProxySettings) : getSystemProxyAgent(url);
126-
return download(zipPath, { url: url, agent: getAgent(url) })
127-
.then(() => validate(zipPath, extension))
128-
.then(manifest => { this._onInstallExtension.fire(manifest); return manifest; })
129-
.then(manifest => extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true }).then(() => manifest))
130-
.then(manifest => {
131-
manifest = assign({ __metadata: galleryInformation }, manifest);
132-
return pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
133-
})
134-
.then(() => { this._onDidInstallExtension.fire(extension); return extension; });
135-
});
125+
const settings = TPromise.join([
126+
UserSettings.getValue(this.contextService, 'http.proxy'),
127+
UserSettings.getValue(this.contextService, 'http.proxy.strictSSL')
128+
]);
129+
130+
return settings
131+
.then(settings => ({ proxyUrl: settings[0], strictSSL: settings[1] }))
132+
.then(options => getProxyAgent(url, options))
133+
.then(agent => download(zipPath, { url, agent }))
134+
.then(() => validate(zipPath, extension))
135+
.then(manifest => { this._onInstallExtension.fire(manifest); return manifest; })
136+
.then(manifest => extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true }).then(() => manifest))
137+
.then(manifest => {
138+
manifest = assign({ __metadata: galleryInformation }, manifest);
139+
return pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
140+
})
141+
.then(() => { this._onDidInstallExtension.fire(extension); return extension; });
136142
}
137143

138144
private installFromZip(zipPath: string): TPromise<IExtension> {

src/vs/workbench/services/request/node/requestService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ confRegistry.registerConfiguration({
125125
'http.proxy': {
126126
'type': 'string',
127127
'description': nls.localize('proxy', "The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables")
128+
},
129+
'http.proxyStrictSSL': {
130+
'type': 'boolean',
131+
'default': true,
132+
'description': nls.localize('strictSSL', "Whether the proxy server certificate should be verified against the list of supplied CAs.")
128133
}
129134
}
130135
});

0 commit comments

Comments
 (0)