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