Path: blob/master/node_modules/agent-base/dist/src/index.d_1.ts
2593 views
/// <reference types="node" />1import net from 'net';2import http from 'http';3import https from 'https';4import { Duplex } from 'stream';5import { EventEmitter } from 'events';6declare function createAgent(opts?: createAgent.AgentOptions): createAgent.Agent;7declare function createAgent(callback: createAgent.AgentCallback, opts?: createAgent.AgentOptions): createAgent.Agent;8declare namespace createAgent {9interface ClientRequest extends http.ClientRequest {10_last?: boolean;11_hadError?: boolean;12method: string;13}14interface AgentRequestOptions {15host?: string;16path?: string;17port: number;18}19interface HttpRequestOptions extends AgentRequestOptions, Omit<http.RequestOptions, keyof AgentRequestOptions> {20secureEndpoint: false;21}22interface HttpsRequestOptions extends AgentRequestOptions, Omit<https.RequestOptions, keyof AgentRequestOptions> {23secureEndpoint: true;24}25type RequestOptions = HttpRequestOptions | HttpsRequestOptions;26type AgentLike = Pick<createAgent.Agent, 'addRequest'> | http.Agent;27type AgentCallbackReturn = Duplex | AgentLike;28type AgentCallbackCallback = (err?: Error | null, socket?: createAgent.AgentCallbackReturn) => void;29type AgentCallbackPromise = (req: createAgent.ClientRequest, opts: createAgent.RequestOptions) => createAgent.AgentCallbackReturn | Promise<createAgent.AgentCallbackReturn>;30type AgentCallback = typeof Agent.prototype.callback;31type AgentOptions = {32timeout?: number;33};34/**35* Base `http.Agent` implementation.36* No pooling/keep-alive is implemented by default.37*38* @param {Function} callback39* @api public40*/41class Agent extends EventEmitter {42timeout: number | null;43maxFreeSockets: number;44maxTotalSockets: number;45maxSockets: number;46sockets: {47[key: string]: net.Socket[];48};49freeSockets: {50[key: string]: net.Socket[];51};52requests: {53[key: string]: http.IncomingMessage[];54};55options: https.AgentOptions;56private promisifiedCallback?;57private explicitDefaultPort?;58private explicitProtocol?;59constructor(callback?: createAgent.AgentCallback | createAgent.AgentOptions, _opts?: createAgent.AgentOptions);60get defaultPort(): number;61set defaultPort(v: number);62get protocol(): string;63set protocol(v: string);64callback(req: createAgent.ClientRequest, opts: createAgent.RequestOptions, fn: createAgent.AgentCallbackCallback): void;65callback(req: createAgent.ClientRequest, opts: createAgent.RequestOptions): createAgent.AgentCallbackReturn | Promise<createAgent.AgentCallbackReturn>;66/**67* Called by node-core's "_http_client.js" module when creating68* a new HTTP request with this Agent instance.69*70* @api public71*/72addRequest(req: ClientRequest, _opts: RequestOptions): void;73freeSocket(socket: net.Socket, opts: AgentOptions): void;74destroy(): void;75}76}77export = createAgent;787980