1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | import { Agent, AgentOptions as HttpsAgentOptions } from 'https';
|
21 | import { AgentOptions as HttpAgentOptions } from 'http';
|
22 | import { PassThrough, Readable } from 'stream';
|
23 | import { TeenyStatistics } from './TeenyStatistics';
|
24 | export interface CoreOptions {
|
25 | method?: string;
|
26 | timeout?: number;
|
27 | gzip?: boolean;
|
28 | json?: any;
|
29 | headers?: Headers;
|
30 | body?: string | {};
|
31 | useQuerystring?: boolean;
|
32 | qs?: any;
|
33 | proxy?: string;
|
34 | multipart?: RequestPart[];
|
35 | forever?: boolean;
|
36 | pool?: HttpsAgentOptions | HttpAgentOptions;
|
37 | }
|
38 | export interface OptionsWithUri extends CoreOptions {
|
39 | uri: string;
|
40 | }
|
41 | export interface OptionsWithUrl extends CoreOptions {
|
42 | url: string;
|
43 | }
|
44 | export type Options = OptionsWithUri | OptionsWithUrl;
|
45 | export interface Request extends PassThrough {
|
46 | agent: Agent | false;
|
47 | headers: Headers;
|
48 | href?: string;
|
49 | }
|
50 | export interface Response<T = any> {
|
51 | statusCode: number;
|
52 | headers: Headers;
|
53 | body: T;
|
54 | request: Request;
|
55 | statusMessage?: string;
|
56 | }
|
57 | export interface RequestPart {
|
58 | body: string | Readable;
|
59 | }
|
60 | export interface RequestCallback<T = any> {
|
61 | (err: Error | null, response: Response, body?: T): void;
|
62 | }
|
63 | export declare class RequestError extends Error {
|
64 | code?: number;
|
65 | }
|
66 | interface Headers {
|
67 | [index: string]: any;
|
68 | }
|
69 | declare function teenyRequest(reqOpts: Options): Request;
|
70 | declare function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
|
71 | declare namespace teenyRequest {
|
72 | var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
|
73 | var stats: TeenyStatistics;
|
74 | var resetStats: () => void;
|
75 | }
|
76 | export { teenyRequest };
|