1 |
|
2 |
|
3 |
|
4 |
|
5 | import caseless = require("caseless");
|
6 | import stream = require("stream");
|
7 | import http = require("http");
|
8 | import https = require("https");
|
9 | import fs = require("fs");
|
10 | import FormData = require("form-data");
|
11 | import net = require("net");
|
12 | import tough = require("tough-cookie");
|
13 | import { Url } from "url";
|
14 |
|
15 | declare namespace request {
|
16 | interface RequestAPI<TRequest extends Request, TOptions extends CoreOptions, TUriUrlOptions> {
|
17 | defaults(options: TOptions): RequestAPI<TRequest, TOptions, RequiredUriUrl>;
|
18 | defaults(options: RequiredUriUrl & TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
19 |
|
20 | (uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
21 | (uri: string, callback?: RequestCallback): TRequest;
|
22 | (options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
23 |
|
24 | get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
25 | get(uri: string, callback?: RequestCallback): TRequest;
|
26 | get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
27 |
|
28 | post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
29 | post(uri: string, callback?: RequestCallback): TRequest;
|
30 | post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
31 |
|
32 | put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
33 | put(uri: string, callback?: RequestCallback): TRequest;
|
34 | put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
35 |
|
36 | head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
37 | head(uri: string, callback?: RequestCallback): TRequest;
|
38 | head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
39 |
|
40 | patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
41 | patch(uri: string, callback?: RequestCallback): TRequest;
|
42 | patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
43 |
|
44 | del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
45 | del(uri: string, callback?: RequestCallback): TRequest;
|
46 | del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
47 |
|
48 | delete(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
49 | delete(uri: string, callback?: RequestCallback): TRequest;
|
50 | delete(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
51 |
|
52 | initParams(uri: string, options?: TOptions, callback?: RequestCallback): RequiredUriUrl & TOptions;
|
53 | initParams(
|
54 | uriOrOpts: string | RequiredUriUrl & TOptions,
|
55 | callback?: RequestCallback,
|
56 | ): RequiredUriUrl & TOptions;
|
57 |
|
58 | forever(agentOptions: any, optionsArg: any): TRequest;
|
59 | jar(store?: any): CookieJar;
|
60 | cookie(str: string): Cookie | undefined;
|
61 |
|
62 | debug: boolean;
|
63 | }
|
64 |
|
65 | interface DefaultUriUrlRequestApi<TRequest extends Request, TOptions extends CoreOptions, TUriUrlOptions>
|
66 | extends RequestAPI<TRequest, TOptions, TUriUrlOptions>
|
67 | {
|
68 | defaults(options: TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
69 | (callback?: RequestCallback): TRequest;
|
70 |
|
71 | get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
72 | get(uri: string, callback?: RequestCallback): TRequest;
|
73 | get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
74 | get(callback?: RequestCallback): TRequest;
|
75 |
|
76 | post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
77 | post(uri: string, callback?: RequestCallback): TRequest;
|
78 | post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
79 | post(callback?: RequestCallback): TRequest;
|
80 |
|
81 | put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
82 | put(uri: string, callback?: RequestCallback): TRequest;
|
83 | put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
84 | put(callback?: RequestCallback): TRequest;
|
85 |
|
86 | head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
87 | head(uri: string, callback?: RequestCallback): TRequest;
|
88 | head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
89 | head(callback?: RequestCallback): TRequest;
|
90 |
|
91 | patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
92 | patch(uri: string, callback?: RequestCallback): TRequest;
|
93 | patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
94 | patch(callback?: RequestCallback): TRequest;
|
95 |
|
96 | del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
97 | del(uri: string, callback?: RequestCallback): TRequest;
|
98 | del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
99 | del(callback?: RequestCallback): TRequest;
|
100 |
|
101 | delete(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
102 | delete(uri: string, callback?: RequestCallback): TRequest;
|
103 | delete(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
104 | delete(callback?: RequestCallback): TRequest;
|
105 | }
|
106 |
|
107 | interface CoreOptions {
|
108 | baseUrl?: string | undefined;
|
109 | callback?: RequestCallback | undefined;
|
110 | jar?: CookieJar | boolean | undefined;
|
111 | formData?: { [key: string]: any } | undefined;
|
112 | form?: { [key: string]: any } | string | undefined;
|
113 | auth?: AuthOptions | undefined;
|
114 | oauth?: OAuthOptions | undefined;
|
115 | aws?: AWSOptions | undefined;
|
116 | hawk?: HawkOptions | undefined;
|
117 | qs?: any;
|
118 | qsStringifyOptions?: any;
|
119 | qsParseOptions?: any;
|
120 | json?: any;
|
121 | jsonReviver?: ((key: string, value: any) => any) | undefined;
|
122 | jsonReplacer?: ((key: string, value: any) => any) | undefined;
|
123 | multipart?: RequestPart[] | Multipart | undefined;
|
124 | agent?: http.Agent | https.Agent | undefined;
|
125 | agentOptions?: http.AgentOptions | https.AgentOptions | undefined;
|
126 | agentClass?: any;
|
127 | forever?: any;
|
128 | host?: string | undefined;
|
129 | port?: number | undefined;
|
130 | method?: string | undefined;
|
131 | headers?: Headers | undefined;
|
132 | body?: any;
|
133 | family?: 4 | 6 | undefined;
|
134 | followRedirect?: boolean | ((response: http.IncomingMessage) => boolean) | undefined;
|
135 | followAllRedirects?: boolean | undefined;
|
136 | followOriginalHttpMethod?: boolean | undefined;
|
137 | maxRedirects?: number | undefined;
|
138 | removeRefererHeader?: boolean | undefined;
|
139 | encoding?: string | null | undefined;
|
140 | pool?: PoolOptions | undefined;
|
141 | timeout?: number | undefined;
|
142 | localAddress?: string | undefined;
|
143 | proxy?: any;
|
144 | tunnel?: boolean | undefined;
|
145 | strictSSL?: boolean | undefined;
|
146 | rejectUnauthorized?: boolean | undefined;
|
147 | time?: boolean | undefined;
|
148 | gzip?: boolean | undefined;
|
149 | preambleCRLF?: boolean | undefined;
|
150 | postambleCRLF?: boolean | undefined;
|
151 | withCredentials?: boolean | undefined;
|
152 | key?: Buffer | undefined;
|
153 | cert?: Buffer | undefined;
|
154 | passphrase?: string | undefined;
|
155 | ca?: string | Buffer | string[] | Buffer[] | undefined;
|
156 | har?: HttpArchiveRequest | undefined;
|
157 | useQuerystring?: boolean | undefined;
|
158 | }
|
159 |
|
160 | interface UriOptions {
|
161 | uri: string | Url;
|
162 | }
|
163 | interface UrlOptions {
|
164 | url: string | Url;
|
165 | }
|
166 | type RequiredUriUrl = UriOptions | UrlOptions;
|
167 |
|
168 | type OptionalUriUrl = RequiredUriUrl | {};
|
169 |
|
170 | type OptionsWithUri = UriOptions & CoreOptions;
|
171 | type OptionsWithUrl = UrlOptions & CoreOptions;
|
172 | type Options = OptionsWithUri | OptionsWithUrl;
|
173 |
|
174 | type MultipartBody = string | Buffer | ArrayBuffer | Uint8Array;
|
175 |
|
176 | type RequestCallback = (error: any, response: Response, body: any) => void;
|
177 |
|
178 | interface HttpArchiveRequest {
|
179 | url?: string | undefined;
|
180 | method?: string | undefined;
|
181 | headers?: NameValuePair[] | undefined;
|
182 | postData?: {
|
183 | mimeType?: string | undefined;
|
184 | params?: NameValuePair[] | undefined;
|
185 | } | undefined;
|
186 | }
|
187 |
|
188 | interface ExtraPoolOptions {
|
189 | maxSockets?: number | undefined;
|
190 | }
|
191 |
|
192 | type PoolOptions = false | { [key: string]: http.Agent | https.Agent } & ExtraPoolOptions | ExtraPoolOptions;
|
193 |
|
194 | interface NameValuePair {
|
195 | name: string;
|
196 | value: string;
|
197 | }
|
198 |
|
199 | interface Multipart {
|
200 | chunked?: boolean | undefined;
|
201 | data?:
|
202 | | Array<{
|
203 | "content-type"?: string | undefined;
|
204 | body: MultipartBody;
|
205 | }>
|
206 | | undefined;
|
207 | }
|
208 |
|
209 | interface RequestPart {
|
210 | headers?: Headers | undefined;
|
211 | body: any;
|
212 | }
|
213 |
|
214 | interface Request extends caseless.Httpified, stream.Stream {
|
215 | readable: boolean;
|
216 | writable: boolean;
|
217 | explicitMethod?: true | undefined;
|
218 |
|
219 | debug(...args: any[]): void;
|
220 | pipeDest(dest: any): void;
|
221 | qs(q: object, clobber?: boolean): Request;
|
222 | form(): FormData;
|
223 | form(form: any): Request;
|
224 | multipart(multipart: RequestPart[]): Request;
|
225 | json(val: any): Request;
|
226 | aws(opts: AWSOptions, now?: boolean): Request;
|
227 | hawk(opts: HawkOptions): void;
|
228 | auth(username: string, password: string, sendImmediately?: boolean, bearer?: string): Request;
|
229 | oauth(oauth: OAuthOptions): Request;
|
230 | jar(jar: CookieJar): Request;
|
231 |
|
232 | on(event: string, listener: (...args: any[]) => void): this;
|
233 | on(event: "request", listener: (req: http.ClientRequest) => void): this;
|
234 | on(event: "response", listener: (resp: Response) => void): this;
|
235 | on(event: "data", listener: (data: Buffer | string) => void): this;
|
236 | on(event: "error", listener: (e: Error) => void): this;
|
237 | on(event: "complete", listener: (resp: Response, body?: string | Buffer) => void): this;
|
238 | on(event: "pipe", listener: (src: stream.Readable) => void): this;
|
239 | on(event: "socket", listener: (src: net.Socket) => void): this;
|
240 |
|
241 | write(buffer: Buffer | string, cb?: (err?: Error) => void): boolean;
|
242 | write(str: string, encoding?: string, cb?: (err?: Error) => void): boolean;
|
243 | end(cb?: () => void): any;
|
244 | end(chunk: string | Buffer, cb?: () => void): any;
|
245 | end(str: string, encoding?: string, cb?: () => void): any;
|
246 |
|
247 | pause(): void;
|
248 | resume(): void;
|
249 | abort(): void;
|
250 | destroy(): void;
|
251 | toJSON(): RequestAsJSON;
|
252 |
|
253 |
|
254 | host?: string | undefined;
|
255 | port?: number | undefined;
|
256 | followAllRedirects?: boolean | undefined;
|
257 | followOriginalHttpMethod?: boolean | undefined;
|
258 | maxRedirects?: number | undefined;
|
259 | removeRefererHeader?: boolean | undefined;
|
260 | encoding?: string | null | undefined;
|
261 | timeout?: number | undefined;
|
262 | localAddress?: string | undefined;
|
263 | strictSSL?: boolean | undefined;
|
264 | rejectUnauthorized?: boolean | undefined;
|
265 | time?: boolean | undefined;
|
266 | gzip?: boolean | undefined;
|
267 | preambleCRLF?: boolean | undefined;
|
268 | postambleCRLF?: boolean | undefined;
|
269 | withCredentials?: boolean | undefined;
|
270 | key?: Buffer | undefined;
|
271 | cert?: Buffer | undefined;
|
272 | passphrase?: string | undefined;
|
273 | ca?: string | Buffer | string[] | Buffer[] | undefined;
|
274 | har?: HttpArchiveRequest | undefined;
|
275 |
|
276 |
|
277 | headers: Headers;
|
278 | method: string;
|
279 | pool: PoolOptions;
|
280 | dests: stream.Readable[];
|
281 | callback?: RequestCallback | undefined;
|
282 | uri: Url & { href: string; pathname: string };
|
283 | proxy: null | string | Url;
|
284 | tunnel: boolean;
|
285 | setHost: boolean;
|
286 | path: string;
|
287 | agent: false | http.Agent | https.Agent;
|
288 | body: Buffer | Buffer[] | string | string[] | stream.Readable;
|
289 | timing?: boolean | undefined;
|
290 | src?: stream.Readable | undefined;
|
291 |
|
292 |
|
293 | href: string;
|
294 | startTime?: number | undefined;
|
295 | startTimeNow?: number | undefined;
|
296 | timings?: {
|
297 | socket: number;
|
298 | lookup: number;
|
299 | connect: number;
|
300 | response: number;
|
301 | end: number;
|
302 | } | undefined;
|
303 |
|
304 |
|
305 | elapsedTime?: number | undefined;
|
306 | response?: Response | undefined;
|
307 | }
|
308 |
|
309 | interface Response extends http.IncomingMessage {
|
310 | statusCode: number;
|
311 | statusMessage: string;
|
312 | request: Request;
|
313 | body: any;
|
314 | caseless: caseless.Caseless;
|
315 | toJSON(): ResponseAsJSON;
|
316 |
|
317 | timingStart?: number | undefined;
|
318 | elapsedTime?: number | undefined;
|
319 | timings?: {
|
320 | socket: number;
|
321 | lookup: number;
|
322 | connect: number;
|
323 | response: number;
|
324 | end: number;
|
325 | } | undefined;
|
326 | timingPhases?: {
|
327 | wait: number;
|
328 | dns: number;
|
329 | tcp: number;
|
330 | firstByte: number;
|
331 | download: number;
|
332 | total: number;
|
333 | } | undefined;
|
334 | }
|
335 |
|
336 |
|
337 | type ResponseRequest = Request;
|
338 | type RequestResponse = Response;
|
339 |
|
340 | interface Headers {
|
341 | [key: string]: any;
|
342 | }
|
343 |
|
344 | interface AuthOptions {
|
345 | user?: string | undefined;
|
346 | username?: string | undefined;
|
347 | pass?: string | undefined;
|
348 | password?: string | undefined;
|
349 | sendImmediately?: boolean | undefined;
|
350 | bearer?: string | (() => string) | undefined;
|
351 | }
|
352 |
|
353 | interface OAuthOptions {
|
354 | callback?: string | undefined;
|
355 | consumer_key?: string | undefined;
|
356 | consumer_secret?: string | undefined;
|
357 | token?: string | undefined;
|
358 | token_secret?: string | undefined;
|
359 | transport_method?: "body" | "header" | "query" | undefined;
|
360 | verifier?: string | undefined;
|
361 | body_hash?: true | string | undefined;
|
362 | }
|
363 |
|
364 | interface HawkOptions {
|
365 | credentials: any;
|
366 | }
|
367 |
|
368 | interface AWSOptions {
|
369 | secret: string;
|
370 | bucket?: string | undefined;
|
371 | }
|
372 |
|
373 | interface RequestAsJSON {
|
374 | uri: Url;
|
375 | method: string;
|
376 | headers: Headers;
|
377 | }
|
378 |
|
379 | interface ResponseAsJSON {
|
380 | statusCode: number;
|
381 | body: any;
|
382 | headers: Headers;
|
383 | request: RequestAsJSON;
|
384 | }
|
385 |
|
386 | type Cookie = tough.Cookie;
|
387 |
|
388 | interface CookieJar {
|
389 | setCookie(cookieOrStr: Cookie | string, uri: string | Url, options?: tough.CookieJar.SetCookieOptions): void;
|
390 | getCookieString(uri: string | Url): string;
|
391 | getCookies(uri: string | Url): Cookie[];
|
392 | }
|
393 | }
|
394 | declare var request: request.RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>;
|
395 | export = request;
|
396 |
|
\ | No newline at end of file |