-
Notifications
You must be signed in to change notification settings - Fork 12
/
Requests.ts
100 lines (85 loc) · 2.4 KB
/
Requests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// The interfaces in this file are intended to be as close as possible to the
// interfaces used for the `fetch` Web API. Doing so should allow implementations
// which are more easily portable.
import type { EventSource, EventSourceInitDict } from './EventSource';
// These are not full specifications of the interface, but instead subsets
// based on the functionality needed by the SDK. Exposure of the full standard
// would require much more per platform implementation for platforms that do not
// natively support fetch.
/**
* Interface for headers that are part of a fetch response.
*/
export interface Headers {
/**
* Get a header by name.
*
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
*
* @param name The name of the header to get.
*/
get(name: string): string | null;
/**
* Returns an iterator allowing iteration of all the keys contained
* in this object.
*
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys
*
*/
keys(): Iterable<string>;
/**
* Returns an iterator allowing iteration of all the values contained
* in this object.
*
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
*/
values(): Iterable<string>;
/**
* Returns an iterator allowing iteration of all the key-value pairs in
* the object.
*
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries
*/
entries(): Iterable<[string, string]>;
/**
* Returns true if the header is present.
* @param name The name of the header to check.
*/
has(name: string): boolean;
}
/**
* Interface for fetch responses.
*/
export interface Response {
headers: Headers;
status: number;
/**
* Read the response and provide it as a string.
*/
text(): Promise<string>;
/**
* Read the response and provide it as decoded json.
*/
json(): Promise<any>;
}
export interface Options {
headers?: Record<string, string>;
method?: string;
body?: string;
timeout?: number;
}
export interface Requests {
fetch(url: string, options?: Options): Promise<Response>;
createEventSource(url: string, eventSourceInitDict: EventSourceInitDict): EventSource;
/**
* Returns true if a proxy is configured.
*/
usingProxy?(): boolean;
/**
* Returns true if the proxy uses authentication.
*/
usingProxyAuth?(): boolean;
}
export interface HttpErrorResponse {
message: string;
status?: number;
}