jimpex
    Preparing search index...

    Class HTTP

    A set of utilities to work with HTTP requests and responses.

    Index

    Constructors

    Properties

    _logger: SimpleLogger

    The service used to log information in the terminal.

    _nodeFetch: (url: URL | RequestInfo, init?: RequestInit) => Promise<Response>

    The node-fetch library. Since it's an ESM only module, Jimpex loads it on boot and makes it available on the container.

    _options: HTTPOptions

    The service customization options.

    Accessors

    Methods

    • Logs a request information into the terminal.

      Parameters

      • url: string

        The request URL.

      • options: RequestInit

        The options for the request.

      Returns void

    • Logs a response information into the terminal.

      Parameters

      • response: Response

        The response to log.

      Returns void

    • Creates a dictionary with all the custom headers a request has. By custom header it means all the headers which name start with x-.

      Parameters

      • req: Request

        The request from which it will try to get the headers.

      • options: GetCustomHeadersFromRequestOptions = {}

        The options to customize the behavior with certain headers.

      Returns Record<string, string>

    • Tries to get the IP address from a given request.

      Parameters

      • req: Request

        The request from which it will try to obtain the IP address.

      Returns string | undefined

    • It takes a dictionary of headers and normalize the names so each word will start with an upper case character. This is helpful in case you added custom headers and didn't care about the casing, or when copying headers from a server request, as they all come transformed into lower case.

      Parameters

      • headers: Record<string, string>

        The dictionary of headers to normalize.

      Returns Record<string, string>