-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathRequest.ts
More file actions
183 lines (174 loc) · 6.32 KB
/
Copy pathRequest.ts
File metadata and controls
183 lines (174 loc) · 6.32 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import type { EventEmitter } from 'node:events';
import type { Readable, Writable } from 'node:stream';
import type { Dispatcher } from 'undici';
import { Request } from 'undici';
import type { IncomingHttpHeaders } from './IncomingHttpHeaders.js';
import type { HttpClientResponse } from './Response.js';
export type HttpMethod = Dispatcher.HttpMethod;
export type RequestURL = string | URL;
export type FixJSONCtlCharsHandler = (data: string) => string;
export type FixJSONCtlChars = boolean | FixJSONCtlCharsHandler;
type AbortSignal = unknown;
export type RequestOptions = {
/** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
method?: HttpMethod | Lowercase<HttpMethod>;
/** Alias for 'method'. */
type?: HttpMethod | Lowercase<HttpMethod>;
/** Data to be sent. Will be stringify automatically. */
data?: any;
/** Manually set the content of payload. If set, data will be ignored. */
content?: string | Buffer | Readable;
/**
* @deprecated
* Stream to be pipe to the remote. If set, data and content will be ignored.
* Alias to `content = Readable`
*/
stream?: Readable;
/**
* A writable stream to be piped by the response stream.
* Responding data will be write to this stream and callback
* will be called with data set null after finished writing.
*/
writeStream?: Writable;
/**
* The files will send with multipart/form-data format, base on formstream.
* If method not set, will use POST method by default.
*/
files?:
| Array<Readable | Buffer | string>
| Record<string, Readable | Buffer | string>
| Readable
| Buffer
| string
| object;
/** Type of request data, could be 'json'. If it's 'json', will auto set Content-Type: 'application/json' header. */
contentType?: string;
/**
* Type of response data. Could be text or json.
* If it's text or html, the callbacked data would be a String.
* If it's json, the data of callback would be a parsed JSON Object
* and will auto set Accept: 'application/json' header.
* Default is 'buffer'.
*/
dataType?: 'text' | 'html' | 'json' | 'buffer' | 'stream';
/**
* urllib default use URLSearchParams to stringify form data which don't support nested object,
* will use qs instead of URLSearchParams to support nested object by set this option to true.
*/
nestedQuerystring?: boolean;
/**
* @deprecated
* Only for d.ts keep compatible with urllib@2, don't use it anymore.
*/
dataAsQueryString?: boolean;
/**
* @deprecated
* Let you get the res object when request connected, default false.
* If set to true, `data` will be response readable stream.
* Alias to `dataType = 'stream'`
*/
streaming?: boolean;
/**
* @deprecated
* Alias to `dataType = 'stream'`
*/
customResponse?: boolean;
/** Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is false. */
fixJSONCtlChars?: FixJSONCtlChars;
/** Request headers. */
headers?: IncomingHttpHeaders;
/**
* Request timeout in milliseconds for connecting phase and response receiving phase.
* Defaults is `5000`, both are 5 seconds. You can use timeout: 5000 to tell urllib use same timeout on two phase or set them separately such as
* timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s.
*/
timeout?: number | number[];
/**
* Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out.
* Monitors time between activity on a connected socket.
* This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
*/
keepAliveTimeout?: number;
/**
* username:password used in HTTP Basic Authorization.
* Alias to `headers.authorization = xxx`
**/
auth?: string;
/**
* username:password used in HTTP Digest Authorization.
* */
digestAuth?: string;
/** follow HTTP 3xx responses as redirects. defaults to true. */
followRedirect?: boolean;
/** The maximum number of redirects to follow, defaults to 10. */
maxRedirects?: number;
/** Format the redirect url by your self. Default is url.resolve(from, to). */
formatRedirectUrl?: (a: any, b: any) => void;
/** Before request hook, you can change every thing here. */
beforeRequest?: (...args: any[]) => void;
/** Accept `gzip, br` response content and auto decode it, default is `false`. */
compressed?: boolean;
/**
* @deprecated
* Alias to compressed
* */
gzip?: boolean;
/**
* Enable timing or not, default is `true`.
* */
timing?: boolean;
/**
* Auto retry times on 5xx response, default is `0`. Don't work on streaming request
* It's not supported by using retry and writeStream, because the retry request can't stop the stream which is consuming.
**/
retry?: number;
/** Wait a delay(ms) between retries */
retryDelay?: number;
/**
* Determine whether retry, a response object as the first argument.
* It will retry when status >= 500 by default. Request error is not included.
*/
isRetry?: (response: HttpClientResponse) => boolean;
/**
* Auto retry times on socket error, default is `1`. Don't work on streaming request
* It's not supported by using retry and writeStream, because the retry request can't stop the stream which is consuming.
**/
socketErrorRetry?: number;
/** Default: `null` */
opaque?: unknown;
/**
* @deprecated
* Maybe you should use opaque instead
*/
ctx?: unknown;
/**
* request dispatcher, default is getGlobalDispatcher()
*/
dispatcher?: Dispatcher;
/**
* unix domain socket file path
*/
socketPath?: string | null;
/** Whether the request should stablish a keep-alive or not. Default `false`, try to keep alive by default */
reset?: boolean;
/** Default: `64 KiB` */
highWaterMark?: number;
signal?: AbortSignal | EventEmitter;
/**
* If `true`, the server certificate is verified against the list of supplied CAs.
* An 'error' event is emitted if verification fails.
* Default: `true`
*/
rejectUnauthorized?: boolean;
};
export type RequestMeta = {
requestId: number;
url: string;
args: RequestOptions;
ctx?: unknown;
retries: number;
};
export type FetchMeta = {
requestId: number;
request: Request;
};