diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts index 531ec2810d0..feb9e070e1b 100644 --- a/src/vs/workbench/browser/web.main.ts +++ b/src/vs/workbench/browser/web.main.ts @@ -40,6 +40,8 @@ import { joinPath } from 'vs/base/common/resources'; import { BrowserStorageService } from 'vs/platform/storage/browser/storageService'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { getThemeTypeSelector, DARK, HIGH_CONTRAST, LIGHT } from 'vs/platform/theme/common/themeService'; +import { IRequestService } from 'vs/platform/request/common/request'; +import { WebRequestService as RequestService } from 'vs/workbench/services/request/browser/requestService'; class CodeRendererMain extends Disposable { @@ -160,7 +162,7 @@ class CodeRendererMain extends Disposable { fileService.registerProvider(Schemas.userData, userDataProvider); } - const services = await Promise.all([ + const [configurationService, storageService] = await Promise.all([ this.createWorkspaceService(payload, environmentService, fileService, remoteAgentService, logService).then(service => { // Workspace @@ -181,7 +183,10 @@ class CodeRendererMain extends Disposable { }) ]); - return { serviceCollection, logService, storageService: services[1] }; + // Request Service + serviceCollection.set(IRequestService, new RequestService(this.configuration.requestHandler, remoteAgentService, configurationService, logService)); + + return { serviceCollection, logService, storageService }; } private async createStorageService(payload: IWorkspaceInitializationPayload, environmentService: IWorkbenchEnvironmentService, fileService: IFileService, logService: ILogService): Promise { diff --git a/src/vs/workbench/services/request/browser/requestService.ts b/src/vs/workbench/services/request/browser/requestService.ts index e19f64feebb..f407c52231d 100644 --- a/src/vs/workbench/services/request/browser/requestService.ts +++ b/src/vs/workbench/services/request/browser/requestService.ts @@ -16,6 +16,7 @@ export class WebRequestService extends RequestService { private readonly remoteRequestChannel: RequestChannelClient | null; constructor( + private readonly requestHandler: ((options: IRequestOptions) => Promise) | undefined, @IRemoteAgentService remoteAgentService: IRemoteAgentService, @IConfigurationService configurationService: IConfigurationService, @ILogService logService: ILogService @@ -26,6 +27,9 @@ export class WebRequestService extends RequestService { } async request(options: IRequestOptions, token: CancellationToken): Promise { + if (this.requestHandler) { + return this.requestHandler(options); + } try { const context = await super.request(options, token); if (this.remoteRequestChannel && context.res.statusCode === 405) { diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 1d4bb760313..e56033f3c73 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -68,8 +68,6 @@ import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService'; import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService'; -import { IRequestService } from 'vs/platform/request/common/request'; -import { RequestService } from 'vs/platform/request/browser/requestService'; import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService'; import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { ILocalizationsService } from 'vs/platform/localizations/common/localizations'; @@ -154,7 +152,6 @@ registerSingleton(ITextResourceConfigurationService, TextResourceConfigurationSe registerSingleton(IAccessibilityService, AccessibilityService, true); registerSingleton(IContextViewService, ContextViewService, true); registerSingleton(IExtensionGalleryService, ExtensionGalleryService, true); -registerSingleton(IRequestService, RequestService, true); registerSingleton(ILifecycleService, LifecycleService); registerSingleton(ILocalizationsService, LocalizationsService); registerSingleton(ISharedProcessService, SharedProcessService, true); diff --git a/src/vs/workbench/workbench.web.api.ts b/src/vs/workbench/workbench.web.api.ts index ae193ae3e26..c2dc14709b6 100644 --- a/src/vs/workbench/workbench.web.api.ts +++ b/src/vs/workbench/workbench.web.api.ts @@ -7,6 +7,7 @@ import 'vs/workbench/workbench.web.main'; import { main } from 'vs/workbench/browser/web.main'; import { UriComponents } from 'vs/base/common/uri'; import { IFileSystemProvider } from 'vs/platform/files/common/files'; +import { IRequestOptions, IRequestContext } from 'vs/platform/request/common/request'; export interface IWorkbenchConstructionOptions { @@ -37,6 +38,12 @@ export interface IWorkbenchConstructionOptions { * state like settings, keybindings, UI state (e.g. opened editors) and snippets. */ userDataProvider?: IFileSystemProvider; + + /** + * Experimental: Optional request handler to handle http requests. + * In case not provided, workbench uses XMLHttpRequest. + */ + requestHandler?: (requestOptions: IRequestOptions) => Promise; } /**