提交 c391faf3 编写于 作者: C Christof Marti

_vscodeSystemProxy option (#60773)

上级 1a1c4979
......@@ -20,6 +20,7 @@ import { ExtHostStorage } from 'vs/workbench/api/node/extHostStorage';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/node/extensionDescriptionRegistry';
import { connectProxyResolver } from 'vs/workbench/node/proxyResolver';
class ExtensionMemento implements IExtensionMemento {
......@@ -163,6 +164,9 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
const apiFactory = createApiFactory(initData, extHostContext, extHostWorkspace, extHostConfiguration, this, this._extHostLogService, this._storage);
initializeExtensionApi(this, apiFactory).then(() => {
// Do this when extension service exists, but extensions are not being activated yet.
return connectProxyResolver(extHostWorkspace, extHostConfiguration, this, this._extHostLogService, this._mainThreadTelemetry);
}).then(() => {
this._activator = new ExtensionsActivator(this._registry, {
showMessage: (severity: Severity, message: string): void => {
......
......@@ -20,7 +20,6 @@ import { ExtensionActivatedByEvent } from 'vs/workbench/api/node/extHostExtensio
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { connectProxyResolver } from 'vs/workbench/node/proxyResolver';
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol';
......@@ -92,7 +91,6 @@ export class ExtensionHostMain {
this._extHostConfiguration = new ExtHostConfiguration(rpcProtocol.getProxy(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration);
const mainThreadTelemetry = rpcProtocol.getProxy(MainContext.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)
......
......@@ -26,7 +26,7 @@ export function connectProxyResolver(
) {
const agent = createProxyAgent(extHostWorkspace, extHostLogService, mainThreadTelemetry);
const lookup = createPatchedModules(extHostConfiguration, agent);
configureModuleLoading(extensionService, lookup);
return configureModuleLoading(extensionService, lookup);
}
function createProxyAgent(
......@@ -85,21 +85,23 @@ function createPatchedModules(extHostConfiguration: ExtHostConfiguration, agent:
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
off: assign({}, http, patches(http, agent, { config: 'off' }, true)),
on: assign({}, http, patches(http, agent, { config: 'on' }, true)),
force: assign({}, http, patches(http, agent, { config: 'force' }, true)),
onRequest: assign({}, http, patches(http, agent, setting, true)),
default: assign(http, patches(http, agent, setting, false)) // 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
off: assign({}, https, patches(https, agent, { config: 'off' }, true)),
on: assign({}, https, patches(https, agent, { config: 'on' }, true)),
force: assign({}, https, patches(https, agent, { config: 'force' }, true)),
onRequest: assign({}, https, patches(https, agent, setting, true)),
default: assign(https, patches(https, agent, setting, false)) // run last
}
};
}
function patches(originals: typeof http | typeof https, agent: http.Agent, setting: { config: string; }) {
function patches(originals: typeof http | typeof https, agent: http.Agent, setting: { config: string; }, onRequest: boolean) {
return {
get: patch(originals.get),
......@@ -108,11 +110,6 @@ function patches(originals: typeof http | typeof https, agent: http.Agent, setti
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);
}
if (typeof url !== 'string' && !(url && (<any>url).searchParams)) {
callback = <any>options;
options = url;
......@@ -124,6 +121,11 @@ function patches(originals: typeof http | typeof https, agent: http.Agent, setti
}
options = options || {};
const config = onRequest && (<any>options)._vscodeSystemProxy || setting.config;
if (config === 'off') {
return original.apply(null, arguments);
}
if (!options.socketPath && (config === 'force' || config === 'on' && !options.agent)) {
if (url) {
const parsed = typeof url === 'string' ? nodeurl.parse(url) : url;
......@@ -145,16 +147,22 @@ function patches(originals: typeof http | typeof https, agent: http.Agent, setti
}
}
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);
}
function configureModuleLoading(extensionService: ExtHostExtensionService, lookup: ReturnType<typeof createPatchedModules>): Promise<void> {
return extensionService.getExtensionPathIndex()
.then(extensionPaths => {
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);
}
const ext = extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
return ext && ext.enableProposedApi && lookup[request][(<any>ext).systemProxy] || lookup[request].default;
};
const modules = lookup[request];
const ext = extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
if (ext && ext.enableProposedApi) {
return modules[(<any>ext).systemProxy] || modules.onRequest;
}
return modules.default;
};
});
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册