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