Web request service

- Redirect requests to server on error
This commit is contained in:
Sandeep Somavarapu
2019-07-14 22:31:19 +02:00
parent bfbd44c541
commit c0e7048e79
3 changed files with 97 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IRequestOptions, IRequestContext } from 'vs/platform/request/common/request';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { RequestChannelClient } from 'vs/platform/request/common/requestIpc';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { RequestService } from 'vs/platform/request/browser/requestService';
export class WebRequestService extends RequestService {
private readonly remoteRequestChannel: RequestChannelClient | null;
constructor(
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
@IConfigurationService configurationService: IConfigurationService,
@ILogService logService: ILogService
) {
super(configurationService, logService);
const connection = remoteAgentService.getConnection();
this.remoteRequestChannel = connection ? new RequestChannelClient(connection.getChannel('request')) : null;
}
async request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
try {
const context = await super.request(options, token);
if (this.remoteRequestChannel && context.res.statusCode === 405) {
return this.remoteRequestChannel.request(options, token);
}
return context;
} catch (error) {
if (this.remoteRequestChannel) {
const result = await this.remoteRequestChannel.request(options, token);
return result;
}
throw error;
}
}
}