1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import stream = require('stream');
|
11 | import http = require('http');
|
12 | import https = require('https');
|
13 | import url = require('url');
|
14 | import fs = require('fs');
|
15 | import FormData = require('form-data');
|
16 | import { Url } from 'url';
|
17 |
|
18 | declare namespace request {
|
19 | export interface RequestAPI<TRequest extends Request,
|
20 | TOptions extends CoreOptions,
|
21 | TUriUrlOptions> {
|
22 |
|
23 | defaults(options: TOptions): RequestAPI<TRequest, TOptions, RequiredUriUrl>;
|
24 | defaults(options: RequiredUriUrl & TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
25 |
|
26 | (uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
27 | (uri: string, callback?: RequestCallback): TRequest;
|
28 | (options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
29 |
|
30 | get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
31 | get(uri: string, callback?: RequestCallback): TRequest;
|
32 | get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
33 |
|
34 | post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
35 | post(uri: string, callback?: RequestCallback): TRequest;
|
36 | post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
37 |
|
38 | put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
39 | put(uri: string, callback?: RequestCallback): TRequest;
|
40 | put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
41 |
|
42 | head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
43 | head(uri: string, callback?: RequestCallback): TRequest;
|
44 | head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
45 |
|
46 | patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
47 | patch(uri: string, callback?: RequestCallback): TRequest;
|
48 | patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
49 |
|
50 | del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
51 | del(uri: string, callback?: RequestCallback): TRequest;
|
52 | del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
53 |
|
54 | delete(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
|
55 | delete(uri: string, callback?: RequestCallback): TRequest;
|
56 | delete(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
|
57 |
|
58 | forever(agentOptions: any, optionsArg: any): TRequest;
|
59 | jar(store?: any): CookieJar;
|
60 | cookie(str: string): Cookie;
|
61 |
|
62 | initParams: any;
|
63 | debug: boolean;
|
64 | }
|
65 |
|
66 | interface DefaultUriUrlRequestApi<TRequest extends Request,
|
67 | TOptions extends CoreOptions,
|
68 | TUriUrlOptions> extends RequestAPI<TRequest, TOptions, TUriUrlOptions> {
|
69 |
|
70 | defaults(options: TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
|
71 | (): TRequest;
|
72 | get(): TRequest;
|
73 | post(): TRequest;
|
74 | put(): TRequest;
|
75 | head(): TRequest;
|
76 | patch(): TRequest;
|
77 | del(): TRequest;
|
78 | }
|
79 |
|
80 | interface CoreOptions {
|
81 | baseUrl?: string;
|
82 | callback?: (error: any, response: RequestResponse, body: any) => void;
|
83 | jar?: any;
|
84 | formData?: any;
|
85 | form?: any;
|
86 | auth?: AuthOptions;
|
87 | oauth?: OAuthOptions;
|
88 | aws?: AWSOptions;
|
89 | hawk?: HawkOptions;
|
90 | qs?: any;
|
91 | qsStringifyOptions?: any;
|
92 | qsParseOptions?: any;
|
93 | json?: any;
|
94 | jsonReviver?: (key: string, value: any) => any;
|
95 | jsonReplacer?: (key: string, value: any) => any;
|
96 | multipart?: RequestPart[] | Multipart;
|
97 | agent?: http.Agent | https.Agent;
|
98 | agentOptions?: any;
|
99 | agentClass?: any;
|
100 | forever?: any;
|
101 | host?: string;
|
102 | port?: number;
|
103 | method?: string;
|
104 | headers?: Headers;
|
105 | body?: any;
|
106 | followRedirect?: boolean | ((response: http.IncomingMessage) => boolean);
|
107 | followAllRedirects?: boolean;
|
108 | maxRedirects?: number;
|
109 | encoding?: string | null;
|
110 | pool?: any;
|
111 | timeout?: number;
|
112 | proxy?: any;
|
113 | strictSSL?: boolean;
|
114 | gzip?: boolean;
|
115 | preambleCRLF?: boolean;
|
116 | postambleCRLF?: boolean;
|
117 | key?: Buffer;
|
118 | cert?: Buffer;
|
119 | passphrase?: string;
|
120 | ca?: string | Buffer | string[] | Buffer[];
|
121 | har?: HttpArchiveRequest;
|
122 | useQuerystring?: boolean;
|
123 | }
|
124 |
|
125 | interface UriOptions {
|
126 | uri: string | Url;
|
127 | }
|
128 | interface UrlOptions {
|
129 | url: string | Url;
|
130 | }
|
131 | export type RequiredUriUrl = UriOptions | UrlOptions;
|
132 |
|
133 | interface OptionalUriUrl {
|
134 | uri?: string;
|
135 | url?: string;
|
136 | }
|
137 |
|
138 | export type OptionsWithUri = UriOptions & CoreOptions;
|
139 | export type OptionsWithUrl = UrlOptions & CoreOptions;
|
140 | export type Options = OptionsWithUri | OptionsWithUrl;
|
141 |
|
142 | export interface RequestCallback {
|
143 | (error: any, response: RequestResponse, body: any): void;
|
144 | }
|
145 |
|
146 | export interface RequestResponse extends http.IncomingMessage {
|
147 | request: Options;
|
148 | body: any;
|
149 | }
|
150 |
|
151 | export interface HttpArchiveRequest {
|
152 | url?: string;
|
153 | method?: string;
|
154 | headers?: NameValuePair[];
|
155 | postData?: {
|
156 | mimeType?: string;
|
157 | params?: NameValuePair[];
|
158 | }
|
159 | }
|
160 |
|
161 | export interface NameValuePair {
|
162 | name: string;
|
163 | value: string;
|
164 | }
|
165 |
|
166 | export interface Multipart {
|
167 | chunked?: boolean;
|
168 | data?: {
|
169 | 'content-type'?: string,
|
170 | body: string
|
171 | }[];
|
172 | }
|
173 |
|
174 | export interface RequestPart {
|
175 | headers?: Headers;
|
176 | body: any;
|
177 | }
|
178 |
|
179 | export interface Request extends stream.Stream {
|
180 | readable: boolean;
|
181 | writable: boolean;
|
182 |
|
183 | getAgent(): http.Agent;
|
184 | //start(): void;
|
185 | //abort(): void;
|
186 | pipeDest(dest: any): void;
|
187 | setHeader(name: string, value: string, clobber?: boolean): Request;
|
188 | setHeaders(headers: Headers): Request;
|
189 | qs(q: Object, clobber?: boolean): Request;
|
190 | form(): FormData;
|
191 | form(form: any): Request;
|
192 | multipart(multipart: RequestPart[]): Request;
|
193 | json(val: any): Request;
|
194 | aws(opts: AWSOptions, now?: boolean): Request;
|
195 | auth(username: string, password: string, sendInmediately?: boolean, bearer?: string): Request;
|
196 | oauth(oauth: OAuthOptions): Request;
|
197 | jar(jar: CookieJar): Request;
|
198 |
|
199 | on(event: string, listener: Function): this;
|
200 | on(event: 'request', listener: (req: http.ClientRequest) => void): this;
|
201 | on(event: 'response', listener: (resp: http.IncomingMessage) => void): this;
|
202 | on(event: 'data', listener: (data: Buffer | string) => void): this;
|
203 | on(event: 'error', listener: (e: Error) => void): this;
|
204 | on(event: 'complete', listener: (resp: http.IncomingMessage, body?: string | Buffer) => void): this;
|
205 |
|
206 | write(buffer: Buffer, cb?: Function): boolean;
|
207 | write(str: string, cb?: Function): boolean;
|
208 | write(str: string, encoding: string, cb?: Function): boolean;
|
209 | write(str: string, encoding?: string, fd?: string): boolean;
|
210 | end(): void;
|
211 | end(chunk: Buffer, cb?: Function): void;
|
212 | end(chunk: string, cb?: Function): void;
|
213 | end(chunk: string, encoding: string, cb?: Function): void;
|
214 | pause(): void;
|
215 | resume(): void;
|
216 | abort(): void;
|
217 | destroy(): void;
|
218 | toJSON(): Object;
|
219 | }
|
220 |
|
221 | export interface Headers {
|
222 | [key: string]: any;
|
223 | }
|
224 |
|
225 | export interface AuthOptions {
|
226 | user?: string;
|
227 | username?: string;
|
228 | pass?: string;
|
229 | password?: string;
|
230 | sendImmediately?: boolean;
|
231 | bearer?: string | (() => string);
|
232 | }
|
233 |
|
234 | export interface OAuthOptions {
|
235 | callback?: string;
|
236 | consumer_key?: string;
|
237 | consumer_secret?: string;
|
238 | token?: string;
|
239 | token_secret?: string;
|
240 | verifier?: string;
|
241 | }
|
242 |
|
243 | export interface HawkOptions {
|
244 | credentials: any;
|
245 | }
|
246 |
|
247 | export interface AWSOptions {
|
248 | secret: string;
|
249 | bucket?: string;
|
250 | }
|
251 |
|
252 | export interface CookieJar {
|
253 | setCookie(cookie: Cookie, uri: string | url.Url, options?: any): void
|
254 | getCookieString(uri: string | url.Url): string
|
255 | getCookies(uri: string | url.Url): Cookie[]
|
256 | }
|
257 |
|
258 | export interface CookieValue {
|
259 | name: string;
|
260 | value: any;
|
261 | httpOnly: boolean;
|
262 | }
|
263 |
|
264 | export interface Cookie extends Array<CookieValue> {
|
265 | constructor(name: string, req: Request): void;
|
266 | str: string;
|
267 | expires: Date;
|
268 | path: string;
|
269 | toString(): string;
|
270 | }
|
271 | }
|
272 | declare var request: request.RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>;
|
273 | export = request;
|
274 |
|
\ | No newline at end of file |