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