提交 1737fde4 编写于 作者: C Christof Marti

Per extension (#60773)

上级 d9342838
......@@ -91,8 +91,8 @@ export class ExtensionHostMain {
this._extHostConfiguration = new ExtHostConfiguration(rpcProtocol.getProxy(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration);
const mainThreadTelemetry = rpcProtocol.getProxy(MainContext.MainThreadTelemetry);
connectProxyResolver(extHostWorkspace, this._extHostConfiguration, this._extHostLogService, mainThreadTelemetry);
this._extensionService = new ExtHostExtensionService(initData, rpcProtocol, extHostWorkspace, this._extHostConfiguration, this._extHostLogService, mainThreadTelemetry);
connectProxyResolver(extHostWorkspace, this._extHostConfiguration, this._extensionService, this._extHostLogService, mainThreadTelemetry);
// error forwarding and stack trace scanning
Error.stackTraceLimit = 100; // increase number of stack frames (from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
......
......@@ -3,17 +3,37 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
import * as http from 'http';
import * as https from 'https';
import * as nodeurl from 'url';
import { assign } from 'vs/base/common/objects';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
import { ProxyAgent } from 'vscode-proxy-agent';
import { MainThreadTelemetryShape } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { URI } from 'vs/base/common/uri';
export function connectProxyResolver(
extHostWorkspace: ExtHostWorkspace,
extHostConfiguration: ExtHostConfiguration,
extensionService: ExtHostExtensionService,
extHostLogService: ExtHostLogService,
mainThreadTelemetry: MainThreadTelemetryShape
) {
const agent = createProxyAgent(extHostWorkspace, extHostLogService, mainThreadTelemetry);
const lookup = createPatchedModules(extHostConfiguration, agent);
configureModuleLoading(extensionService, lookup);
}
export function connectProxyResolver(extHostWorkspace: ExtHostWorkspace, extHostConfiguration: ExtHostConfiguration, extHostLogService: ExtHostLogService, mainThreadTelemetry: MainThreadTelemetryShape) {
function createProxyAgent(
extHostWorkspace: ExtHostWorkspace,
extHostLogService: ExtHostLogService,
mainThreadTelemetry: MainThreadTelemetryShape
) {
let timeout: NodeJS.Timer | undefined;
let count = 0;
let duration = 0;
......@@ -50,15 +70,45 @@ export function connectProxyResolver(extHostWorkspace: ExtHostWorkspace, extHost
});
}
const agent = new ProxyAgent({ resolveProxy });
return new ProxyAgent({ resolveProxy });
}
let config = extHostConfiguration.getConfiguration('http').get('systemProxy') || 'off';
function createPatchedModules(extHostConfiguration: ExtHostConfiguration, agent: http.Agent) {
const setting = {
config: extHostConfiguration.getConfiguration('http')
.get<string>('systemProxy') || 'off'
};
extHostConfiguration.onDidChangeConfiguration(e => {
config = extHostConfiguration.getConfiguration('http').get('systemProxy') || 'off';
setting.config = extHostConfiguration.getConfiguration('http')
.get<string>('systemProxy') || 'off';
});
return {
http: {
off: assign({}, http),
on: assign({}, http, patches(http, agent, { config: 'on' })),
force: assign({}, http, patches(http, agent, { config: 'force' })),
default: assign(http, patches(http, agent, setting)) // run last
},
https: {
off: assign({}, https),
on: assign({}, https, patches(https, agent, { config: 'on' })),
force: assign({}, https, patches(https, agent, { config: 'force' })),
default: assign(https, patches(https, agent, setting)) // run last
}
};
}
function patches(originals: typeof http | typeof https, agent: http.Agent, setting: { config: string; }) {
return {
get: patch(originals.get),
request: patch(originals.request)
};
function patch(original: typeof http.get) {
function patched(url: string | URL, options?: http.RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest {
const { config } = setting;
if (config === 'off') {
return original.apply(null, arguments);
}
......@@ -93,9 +143,18 @@ export function connectProxyResolver(extHostWorkspace: ExtHostWorkspace, extHost
}
return patched;
}
}
async function configureModuleLoading(extensionService: ExtHostExtensionService, lookup: ReturnType<typeof createPatchedModules>): Promise<void> {
const extensionPaths = await extensionService.getExtensionPathIndex();
const node_module = <any>require.__$__nodeRequire('module');
const original = node_module._load;
node_module._load = function load(request: string, parent: any, isMain: any) {
if (request !== 'http' && request !== 'https') {
return original.apply(this, arguments);
}
(<any>http).get = patch(http.get);
(<any>http).request = patch(http.request);
(<any>https).get = patch(https.get);
(<any>https).request = patch(https.request);
const ext = extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
return ext && ext.enableProposedApi && lookup[request][(<any>ext).systemProxy] || lookup[request].default;
};
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册