mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 * disable strict null check
This commit is contained in:
122
src/vs/platform/request/common/request.ts
Normal file
122
src/vs/platform/request/common/request.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { VSBufferReadableStream, streamToBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
export const IRequestService = createDecorator<IRequestService>('requestService');
|
||||
|
||||
export interface IHeaders {
|
||||
[header: string]: string;
|
||||
}
|
||||
|
||||
export interface IRequestOptions {
|
||||
type?: string;
|
||||
url?: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
headers?: IHeaders;
|
||||
timeout?: number;
|
||||
data?: string;
|
||||
followRedirects?: number;
|
||||
}
|
||||
|
||||
export interface IRequestContext {
|
||||
res: {
|
||||
headers: IHeaders;
|
||||
statusCode?: number;
|
||||
};
|
||||
stream: VSBufferReadableStream;
|
||||
}
|
||||
|
||||
export interface IRequestService {
|
||||
_serviceBrand: any;
|
||||
|
||||
request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext>;
|
||||
}
|
||||
|
||||
function isSuccess(context: IRequestContext): boolean {
|
||||
return (context.res.statusCode && context.res.statusCode >= 200 && context.res.statusCode < 300) || context.res.statusCode === 1223;
|
||||
}
|
||||
|
||||
function hasNoContent(context: IRequestContext): boolean {
|
||||
return context.res.statusCode === 204;
|
||||
}
|
||||
|
||||
export async function asText(context: IRequestContext): Promise<string | null> {
|
||||
if (!isSuccess(context)) {
|
||||
throw new Error('Server returned ' + context.res.statusCode);
|
||||
}
|
||||
if (hasNoContent(context)) {
|
||||
return null;
|
||||
}
|
||||
const buffer = await streamToBuffer(context.stream);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
export async function asJson<T = {}>(context: IRequestContext): Promise<T | null> {
|
||||
if (!isSuccess(context)) {
|
||||
throw new Error('Server returned ' + context.res.statusCode);
|
||||
}
|
||||
if (hasNoContent(context)) {
|
||||
return null;
|
||||
}
|
||||
const buffer = await streamToBuffer(context.stream);
|
||||
return JSON.parse(buffer.toString());
|
||||
}
|
||||
|
||||
|
||||
export interface IHTTPConfiguration {
|
||||
http?: {
|
||||
proxy?: string;
|
||||
proxyStrictSSL?: boolean;
|
||||
proxyAuthorization?: string;
|
||||
};
|
||||
}
|
||||
|
||||
Registry.as<IConfigurationRegistry>(Extensions.Configuration)
|
||||
.registerConfiguration({
|
||||
id: 'http',
|
||||
order: 15,
|
||||
title: localize('httpConfigurationTitle', "HTTP"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
'http.proxy': {
|
||||
type: 'string',
|
||||
pattern: '^https?://([^:]*(:[^@]*)?@)?([^:]+)(:\\d+)?/?$|^$',
|
||||
description: localize('proxy', "The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables.")
|
||||
},
|
||||
'http.proxyStrictSSL': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: localize('strictSSL', "Controls whether the proxy server certificate should be verified against the list of supplied CAs.")
|
||||
},
|
||||
'http.proxyAuthorization': {
|
||||
type: ['null', 'string'],
|
||||
default: null,
|
||||
description: localize('proxyAuthorization', "The value to send as the 'Proxy-Authorization' header for every network request.")
|
||||
},
|
||||
'http.proxySupport': {
|
||||
type: 'string',
|
||||
enum: ['off', 'on', 'override'],
|
||||
enumDescriptions: [
|
||||
localize('proxySupportOff', "Disable proxy support for extensions."),
|
||||
localize('proxySupportOn', "Enable proxy support for extensions."),
|
||||
localize('proxySupportOverride', "Enable proxy support for extensions, override request options."),
|
||||
],
|
||||
default: 'override',
|
||||
description: localize('proxySupport', "Use the proxy support for extensions.")
|
||||
},
|
||||
'http.systemCertificates': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: localize('systemCertificates', "Controls whether CA certificates should be loaded from the OS. (On Windows and macOS a reload of the window is required after turning this off.)")
|
||||
}
|
||||
}
|
||||
});
|
||||
51
src/vs/platform/request/common/requestIpc.ts
Normal file
51
src/vs/platform/request/common/requestIpc.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IRequestService, IRequestOptions, IRequestContext, IHeaders } from 'vs/platform/request/common/request';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { VSBuffer, bufferToStream, streamToBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
type RequestResponse = [
|
||||
{
|
||||
headers: IHeaders;
|
||||
statusCode?: number;
|
||||
},
|
||||
VSBuffer
|
||||
];
|
||||
|
||||
export class RequestChannel implements IServerChannel {
|
||||
|
||||
constructor(private readonly service: IRequestService) { }
|
||||
|
||||
listen(context: any, event: string): Event<any> {
|
||||
throw new Error('Invalid listen');
|
||||
}
|
||||
|
||||
call(context: any, command: string, args?: any): Promise<any> {
|
||||
switch (command) {
|
||||
case 'request': return this.service.request(args[0], CancellationToken.None)
|
||||
.then(async ({ res, stream }) => {
|
||||
const buffer = await streamToBuffer(stream);
|
||||
return <RequestResponse>[{ statusCode: res.statusCode, headers: res.headers }, buffer];
|
||||
});
|
||||
}
|
||||
throw new Error('Invalid call');
|
||||
}
|
||||
}
|
||||
|
||||
export class RequestChannelClient {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private readonly channel: IChannel) { }
|
||||
|
||||
async request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
|
||||
const [res, buffer] = await this.channel.call<RequestResponse>('request', [options]);
|
||||
return { res, stream: bufferToStream(buffer) };
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user