UNPKG

2.4 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/// <reference types="node" />
18/// <reference types="node" />
19/// <reference types="node" />
20import { Agent, AgentOptions as HttpsAgentOptions } from 'https';
21import { AgentOptions as HttpAgentOptions } from 'http';
22import { PassThrough, Readable } from 'stream';
23import { TeenyStatistics } from './TeenyStatistics';
24export 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}
38export interface OptionsWithUri extends CoreOptions {
39 uri: string;
40}
41export interface OptionsWithUrl extends CoreOptions {
42 url: string;
43}
44export type Options = OptionsWithUri | OptionsWithUrl;
45export interface Request extends PassThrough {
46 agent: Agent | false;
47 headers: Headers;
48 href?: string;
49}
50export interface Response<T = any> {
51 statusCode: number;
52 headers: Headers;
53 body: T;
54 request: Request;
55 statusMessage?: string;
56}
57export interface RequestPart {
58 body: string | Readable;
59}
60export interface RequestCallback<T = any> {
61 (err: Error | null, response: Response, body?: T): void;
62}
63export declare class RequestError extends Error {
64 code?: number;
65}
66interface Headers {
67 [index: string]: any;
68}
69declare function teenyRequest(reqOpts: Options): Request;
70declare function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
71declare namespace teenyRequest {
72 var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
73 var stats: TeenyStatistics;
74 var resetStats: () => void;
75}
76export { teenyRequest };