• Version 6.0.2
  • Published
  • 34.6 kB
  • 1 dependency
  • MIT license


npm i agent-base
yarn add agent-base
pnpm add agent-base


Turn a function into an `http.Agent` instance



function createAgent

createAgent: typeof createAgent;


    class Agent

    class Agent extends EventEmitter {}
    • Base http.Agent implementation. No pooling/keep-alive is implemented by default.

      Parameter callback



    | {
    req: ClientRequest,
    opts: RequestOptions,
    fn: AgentCallbackCallback
    ): void;
    (req: ClientRequest, opts: RequestOptions): any;
    | AgentOptions,
    _opts?: AgentOptions

      property defaultPort

      defaultPort: number;

        property freeSockets

        freeSockets: { [key: string]: net.Socket[] };

          property maxFreeSockets

          maxFreeSockets: number;

            property maxSockets

            maxSockets: number;

              property maxTotalSockets

              maxTotalSockets: number;

                property options

                options: https.AgentOptions;

                  property protocol

                  protocol: string;

                    property requests

                    requests: { [key: string]: http.IncomingMessage[] };

                      property sockets

                      sockets: { [key: string]: net.Socket[] };

                        property timeout

                        timeout: number;

                          method addRequest

                          addRequest: (req: ClientRequest, _opts: RequestOptions) => void;
                          • Called by node-core's "_http_client.js" module when creating a new HTTP request with this Agent instance.


                          method callback

                          callback: {
                          (req: ClientRequest, opts: RequestOptions, fn: AgentCallbackCallback): void;
                          (req: ClientRequest, opts: RequestOptions): any;

                            method destroy

                            destroy: () => void;

                              method freeSocket

                              freeSocket: (socket: net.Socket, opts: AgentOptions) => void;


                                interface AgentRequestOptions

                                interface AgentRequestOptions {}

                                  property host

                                  host?: string;

                                    property path

                                    path?: string;

                                      property port

                                      port: number;

                                        interface ClientRequest

                                        interface ClientRequest extends http.ClientRequest {}

                                          property method

                                          method: string;

                                            interface HttpRequestOptions

                                            interface HttpRequestOptions
                                            extends AgentRequestOptions,
                                            Omit<http.RequestOptions, keyof AgentRequestOptions> {}

                                              property secureEndpoint

                                              secureEndpoint: false;

                                                interface HttpsRequestOptions

                                                interface HttpsRequestOptions
                                                extends AgentRequestOptions,
                                                Omit<https.RequestOptions, keyof AgentRequestOptions> {}

                                                  property secureEndpoint

                                                  secureEndpoint: true;

                                                    Type Aliases

                                                    type AgentCallback

                                                    type AgentCallback = typeof Agent.prototype.callback;

                                                      type AgentCallbackCallback

                                                      type AgentCallbackCallback = (
                                                      err?: Error | null,
                                                      socket?: createAgent.AgentCallbackReturn
                                                      ) => void;

                                                        type AgentCallbackPromise

                                                        type AgentCallbackPromise = (
                                                        req: createAgent.ClientRequest,
                                                        opts: createAgent.RequestOptions
                                                        ) => createAgent.AgentCallbackReturn | Promise<createAgent.AgentCallbackReturn>;

                                                          type AgentCallbackReturn

                                                          type AgentCallbackReturn = Duplex | AgentLike;

                                                            type AgentLike

                                                            type AgentLike = Pick<createAgent.Agent, 'addRequest'> | http.Agent;

                                                              type AgentOptions

                                                              type AgentOptions = {
                                                              timeout?: number;

                                                                type RequestOptions

                                                                type RequestOptions = HttpRequestOptions | HttpsRequestOptions;

                                                                  Package Files (1)

                                                                  Dependencies (1)

                                                                  Dev Dependencies (21)

                                                                  Peer Dependencies (0)

                                                                  No peer dependencies.


                                                                  To add a badge like this badgeto your package's README, use the codes available below.

                                                                  You may also use to create a custom badge linking to

                                                                  • Markdown
                                                                  • HTML
                                                                    <a href=""><img src="" alt=""></a>