@types/http-proxy

  • Version 1.17.15
  • Published
  • 14.5 kB
  • 1 dependency
  • MIT license

Install

npm i @types/http-proxy
yarn add @types/http-proxy
pnpm add @types/http-proxy

Overview

TypeScript definitions for http-proxy

Index

Classes

class Server

class Server<
TIncomingMessage = http.IncomingMessage,
TServerResponse = http.ServerResponse
> extends events.EventEmitter {}

    constructor

    constructor(options?: Server.ServerOptions);
    • Creates the proxy server with specified options.

      Parameter options

      Config object passed to the proxy

    method addListener

    addListener: (event: string, listener: () => void) => this;

      method close

      close: (callback?: () => void) => void;
      • A function that closes the inner webserver and stops listening on given port

      method createProxy

      static createProxy: <
      TIncomingMessage = http.IncomingMessage,
      TServerResponse = http.ServerResponse
      >(
      options?: Server.ServerOptions
      ) => Server<TIncomingMessage, TServerResponse>;
      • Creates the proxy server with specified options.

        Parameter options

        Config object passed to the proxy

        Returns

        Proxy object with handlers for ws and web requests

      method createProxyServer

      static createProxyServer: <
      TIncomingMessage = http.IncomingMessage,
      TServerResponse = http.ServerResponse
      >(
      options?: Server.ServerOptions
      ) => Server<TIncomingMessage, TServerResponse>;
      • Creates the proxy server with specified options.

        Parameter options

        Config object passed to the proxy

        Returns

        Proxy object with handlers for ws and web requests

      method createServer

      static createServer: <
      TIncomingMessage = http.IncomingMessage,
      TServerResponse = http.ServerResponse
      >(
      options?: Server.ServerOptions
      ) => Server<TIncomingMessage, TServerResponse>;
      • Creates the proxy server with specified options.

        Parameter options

        Config object passed to the proxy

        Returns

        Proxy object with handlers for ws and web requests

      method emit

      emit: (event: string, ...args: any[]) => boolean;

        method getMaxListeners

        getMaxListeners: () => number;

          method listen

          listen: (
          port: number,
          hostname?: string
          ) => Server<TIncomingMessage, TServerResponse>;
          • A function that wraps the object in a webserver, for your convenience

            Parameter port

            Port to listen on

            Parameter hostname

            The hostname to listen on

          method listenerCount

          listenerCount: (type: string) => number;

            method listeners

            listeners: (event: string) => Array<() => void>;

              method on

              on: {
              (event: string, listener: () => void): this;
              (
              event: 'error',
              listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>
              ): this;
              (
              event: 'start',
              listener: Server.StartCallback<TIncomingMessage, TServerResponse>
              ): this;
              (
              event: 'proxyReq',
              listener: Server.ProxyReqCallback<
              http.ClientRequest,
              TIncomingMessage,
              TServerResponse
              >
              ): this;
              (
              event: 'proxyRes',
              listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>
              ): this;
              (
              event: 'proxyReqWs',
              listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>
              ): this;
              (
              event: 'econnreset',
              listener: Server.EconnresetCallback<
              Error,
              TIncomingMessage,
              TServerResponse
              >
              ): this;
              (
              event: 'end',
              listener: Server.EndCallback<TIncomingMessage, TServerResponse>
              ): this;
              (event: 'open', listener: Server.OpenCallback): this;
              (event: 'close', listener: Server.CloseCallback<TIncomingMessage>): this;
              };

                method once

                once: {
                (event: string, listener: () => void): this;
                (
                event: 'error',
                listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>
                ): this;
                (
                event: 'start',
                listener: Server.StartCallback<TIncomingMessage, TServerResponse>
                ): this;
                (
                event: 'proxyReq',
                listener: Server.ProxyReqCallback<
                http.ClientRequest,
                TIncomingMessage,
                TServerResponse
                >
                ): this;
                (
                event: 'proxyRes',
                listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>
                ): this;
                (
                event: 'proxyReqWs',
                listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>
                ): this;
                (
                event: 'econnreset',
                listener: Server.EconnresetCallback<
                Error,
                TIncomingMessage,
                TServerResponse
                >
                ): this;
                (
                event: 'end',
                listener: Server.EndCallback<TIncomingMessage, TServerResponse>
                ): this;
                (event: 'open', listener: Server.OpenCallback): this;
                (event: 'close', listener: Server.CloseCallback<TIncomingMessage>): this;
                };

                  method removeAllListeners

                  removeAllListeners: (event?: string) => this;

                    method removeListener

                    removeListener: (event: string, listener: () => void) => this;

                      method setMaxListeners

                      setMaxListeners: (n: number) => this;

                        method web

                        web: (
                        req: http.IncomingMessage,
                        res: http.ServerResponse,
                        options?: Server.ServerOptions,
                        callback?: Server.ErrorCallback
                        ) => void;
                        • Used for proxying regular HTTP(S) requests

                          Parameter req

                          Client request.

                          Parameter res

                          Client response.

                          Parameter options

                          Additional options.

                        method ws

                        ws: (
                        req: http.IncomingMessage,
                        socket: any,
                        head: any,
                        options?: Server.ServerOptions,
                        callback?: Server.ErrorCallback
                        ) => void;
                        • Used for proxying regular HTTP(S) requests

                          Parameter req

                          Client request.

                          Parameter socket

                          Client socket.

                          Parameter head

                          Client head.

                          Parameter options

                          Additionnal options.

                        Interfaces

                        interface ServerOptions

                        interface ServerOptions {}

                          property agent

                          agent?: any;
                          • Object to be passed to http(s).request.

                          property auth

                          auth?: string | undefined;
                          • Basic authentication i.e. 'user:password' to compute an Authorization header.

                          property autoRewrite

                          autoRewrite?: boolean | undefined;
                          • Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false.

                          property buffer

                          buffer?: stream.Stream | undefined;
                          • Buffer

                          property changeOrigin

                          changeOrigin?: boolean | undefined;
                          • Changes the origin of the host header to the target URL.

                          property cookieDomainRewrite

                          cookieDomainRewrite?:
                          | false
                          | string
                          | { [oldDomain: string]: string }
                          | undefined;
                          • rewrites domain of set-cookie headers.

                          property cookiePathRewrite

                          cookiePathRewrite?: false | string | { [oldPath: string]: string } | undefined;
                          • rewrites path of set-cookie headers. Default: false

                          property followRedirects

                          followRedirects?: boolean | undefined;
                          • Specify whether you want to follow redirects. Default: false

                          property forward

                          forward?: ProxyTargetUrl | undefined;
                          • URL string to be parsed with the url module.

                          property headers

                          headers?: { [header: string]: string } | undefined;
                          • object with extra headers to be added to target requests.

                          property hostRewrite

                          hostRewrite?: string | undefined;
                          • Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null.

                          property ignorePath

                          ignorePath?: boolean | undefined;
                          • Specify whether you want to ignore the proxy path of the incoming request.

                          property localAddress

                          localAddress?: string | undefined;
                          • Local interface string to bind for outgoing connections.

                          property method

                          method?: string | undefined;
                          • Explicitly set the method type of the ProxyReq

                          property prependPath

                          prependPath?: boolean | undefined;
                          • Specify whether you want to prepend the target's path to the proxy path.

                          property preserveHeaderKeyCase

                          preserveHeaderKeyCase?: boolean | undefined;
                          • specify whether you want to keep letter case of response header key

                          property protocolRewrite

                          protocolRewrite?: string | undefined;
                          • Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null.

                          property proxyTimeout

                          proxyTimeout?: number | undefined;
                          • Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes)

                          property secure

                          secure?: boolean | undefined;
                          • Verify SSL certificate.

                          property selfHandleResponse

                          selfHandleResponse?: boolean | undefined;
                          • If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event

                          property ssl

                          ssl?: any;
                          • Object to be passed to https.createServer().

                          property target

                          target?: ProxyTarget | undefined;
                          • URL string to be parsed with the url module.

                          property timeout

                          timeout?: number | undefined;
                          • Timeout (in milliseconds) for incoming requests

                          property toProxy

                          toProxy?: boolean | undefined;
                          • Explicitly specify if we are proxying to another proxy.

                          property ws

                          ws?: boolean | undefined;
                          • If you want to proxy websockets.

                          property xfwd

                          xfwd?: boolean | undefined;
                          • Adds x- forward headers.

                          Type Aliases

                          type CloseCallback

                          type CloseCallback<TIncomingMessage = http.IncomingMessage> = (
                          proxyRes: TIncomingMessage,
                          proxySocket: net.Socket,
                          proxyHead: any
                          ) => void;

                            type EconnresetCallback

                            type EconnresetCallback<
                            TError = Error,
                            TIncomingMessage = http.IncomingMessage,
                            TServerResponse = http.ServerResponse
                            > = (
                            err: TError,
                            req: TIncomingMessage,
                            res: TServerResponse,
                            target: ProxyTargetUrl
                            ) => void;

                              type EndCallback

                              type EndCallback<
                              TIncomingMessage = http.IncomingMessage,
                              TServerResponse = http.ServerResponse
                              > = (
                              req: TIncomingMessage,
                              res: TServerResponse,
                              proxyRes: TIncomingMessage
                              ) => void;

                                type ErrorCallback

                                type ErrorCallback<
                                TError = Error,
                                TIncomingMessage = http.IncomingMessage,
                                TServerResponse = http.ServerResponse
                                > = (
                                err: TError,
                                req: TIncomingMessage,
                                res: TServerResponse | net.Socket,
                                target?: ProxyTargetUrl
                                ) => void;

                                  type OpenCallback

                                  type OpenCallback = (proxySocket: net.Socket) => void;

                                    type ProxyReqCallback

                                    type ProxyReqCallback<
                                    TClientRequest = http.ClientRequest,
                                    TIncomingMessage = http.IncomingMessage,
                                    TServerResponse = http.ServerResponse
                                    > = (
                                    proxyReq: TClientRequest,
                                    req: TIncomingMessage,
                                    res: TServerResponse,
                                    options: ServerOptions
                                    ) => void;

                                      type ProxyReqWsCallback

                                      type ProxyReqWsCallback<
                                      TClientRequest = http.ClientRequest,
                                      TIncomingMessage = http.IncomingMessage
                                      > = (
                                      proxyReq: TClientRequest,
                                      req: TIncomingMessage,
                                      socket: net.Socket,
                                      options: ServerOptions,
                                      head: any
                                      ) => void;

                                        type ProxyResCallback

                                        type ProxyResCallback<
                                        TIncomingMessage = http.IncomingMessage,
                                        TServerResponse = http.ServerResponse
                                        > = (
                                        proxyRes: TIncomingMessage,
                                        req: TIncomingMessage,
                                        res: TServerResponse
                                        ) => void;

                                          type ProxyTarget

                                          type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;

                                            type ProxyTargetUrl

                                            type ProxyTargetUrl = string | Partial<url.Url>;

                                              type StartCallback

                                              type StartCallback<
                                              TIncomingMessage = http.IncomingMessage,
                                              TServerResponse = http.ServerResponse
                                              > = (req: TIncomingMessage, res: TServerResponse, target: ProxyTargetUrl) => void;

                                                Package Files (1)

                                                Dependencies (1)

                                                Dev Dependencies (0)

                                                No dev dependencies.

                                                Peer Dependencies (0)

                                                No peer dependencies.

                                                Badge

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

                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/http-proxy.

                                                • Markdown
                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/http-proxy)
                                                • HTML
                                                  <a href="https://www.jsdocs.io/package/@types/http-proxy"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>