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