UNPKG

2.3 kBTypeScriptView Raw
1/*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
5export interface XHROptions {
6 type?: string;
7 url: string;
8 user?: string;
9 password?: string;
10 headers?: Headers;
11 timeout?: number;
12 data?: string;
13 strictSSL?: boolean;
14 followRedirects?: number;
15 token?: CancellationToken;
16 agent?: HttpProxyAgent | HttpsProxyAgent;
17}
18
19export interface XHRResponse {
20 readonly responseText: string;
21 readonly body: Uint8Array;
22 readonly status: number;
23 readonly headers: Headers;
24}
25
26export interface XHRRequest {
27 (options: XHROptions): Promise<XHRResponse>
28}
29
30export interface XHRConfigure {
31 (proxyUrl: string | undefined, strictSSL: boolean): void;
32}
33
34export interface Disposable {
35 /**
36 * Dispose this object.
37 */
38 dispose(): void;
39}
40/**
41 * Represents a typed event.
42 */
43 export interface Event<T> {
44 /**
45 *
46 * @param listener The listener function will be call when the event happens.
47 * @param thisArgs The 'this' which will be used when calling the event listener.
48 * @param disposables An array to which a {{IDisposable}} will be added. The
49 * @return
50 */
51 (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
52}
53/**
54 * Defines a CancellationToken. This interface is not
55 * intended to be implemented. A CancellationToken must
56 * be created via a CancellationTokenSource.
57 */
58 export interface CancellationToken {
59 /**
60 * Is `true` when the token has been cancelled, `false` otherwise.
61 */
62 readonly isCancellationRequested: boolean;
63 /**
64 * An [event](#Event) which fires upon cancellation.
65 */
66 readonly onCancellationRequested: Event<any>;
67}
68
69export type HttpProxyAgent = any;
70
71export type HttpsProxyAgent = any;
72
73export type Headers = { [header: string]: string | string[] | undefined };
74
75export declare const configure: XHRConfigure;
76export declare const xhr: XHRRequest;
77
78export declare function getErrorStatusDescription(status: number): string;