import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex } from '../../index-DAUqbQ6h.js'; import { Request } from 'express'; import { NodeFetch } from '../../types/http.js'; import { SimpleLogger } from '@homer0/simple-logger'; import { BodyInit, Response, RequestInit } from 'node-fetch'; import '../../types/express.js'; import '../../types/utils.js'; import '@homer0/path-utils'; import '@homer0/simple-config'; import '@homer0/events-hub'; import 'https'; import 'http'; import 'spdy'; /** * The options to customize the service. * * @group Services/HTTP */ type HTTPOptions = { /** * Whether or not the service should log the requests and their responses. */ logRequests?: boolean; }; /** * The options to construct a {@link HTTP}. * * @group Services/HTTP */ type HTTPConstructorOptions = Partial & { /** * A dictionary with the dependencies to inject. */ inject: { logger: SimpleLogger; nodeFetch: NodeFetch; }; }; /** * The allowed formats for the body of a request. * * @group Services/HTTP */ type HTTPFetchBody = string | Record | BodyInit; /** * The options for a request. * * @group Services/HTTP */ type HTTPFetchOptions = { /** * The HTTP method. * * @default 'GET' */ method?: string; /** * The headers dictionary. */ headers?: Record; /** * The body of the request. */ body?: HTTPFetchBody; /** * A dictionary of query string parameters. */ qs?: Record; /** * A request object generated by the application. This can be used to copy information * like custom headers or the IP (for the X-Forwarded-For header). */ req?: Request; }; /** * The options for the method that extracts custom headers from a request. * * @group Services/HTTP */ type GetCustomHeadersFromRequestOptions = { /** * Since the method considers all headers that start with `x-` as custom headers, * setting this to `false` is the only way to exclude `x-forwarded-` headers from the * list. * * @default false */ includeXForwardedHeaders?: boolean; }; /** * A set of utilities to work with HTTP requests and responses. * * @group Services * @group Services/HTTP */ declare class HTTP { /** * The service used to log information in the terminal. */ protected readonly _logger: SimpleLogger; /** * The node-fetch library. Since it's an ESM only module, Jimpex loads it on boot and makes * it available on the container. */ protected readonly _nodeFetch: NodeFetch; /** * The service customization options. */ protected readonly _options: HTTPOptions; /** * @param options The options to construct the class. */ constructor({ inject: { logger, nodeFetch }, ...options }: HTTPConstructorOptions); /** * Makes a fetch request. * * @param url The URL to fetch. * @param options The custom options for the request. */ fetch(url: string, options?: HTTPFetchOptions): Promise; /** * Tries to get the IP address from a given request. * * @param req The request from which it will try to obtain the IP address. */ getIPFromRequest(req: Request): string | undefined; /** * Creates a dictionary with all the custom headers a request has. By custom header it * means all the headers which name start with `x-`. * * @param req The request from which it will try to get the headers. * @param options The options to customize the behavior with certain headers. */ getCustomHeadersFromRequest(req: Request, options?: GetCustomHeadersFromRequestOptions): Record; /** * 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. * * @param headers The dictionary of headers to normalize. */ normalizeHeaders(headers: Record): Record; /** * The customization options. */ get options(): Readonly; /** * Logs a request information into the terminal. * * @param url The request URL. * @param options The options for the request. */ protected _logRequest(url: string, options: RequestInit): void; /** * Logs a response information into the terminal. * * @param response The response to log. */ protected _logResponse(response: Response): void; } /** * The service provider that once registered on the container will set an instance of * {@link HTTP} as the `http` service. The provider also checks the `debug.logRequests` * setting on the application configuration in order to enable or not the logging of * requests/responses. * * @example * * // Register it on the container * container.register(httpProvider); * // Getting access to the service instance * const http = container.get('http'); * * @group Providers * @group Services/HTTP */ declare const httpProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn>; export { type GetCustomHeadersFromRequestOptions, HTTP, type HTTPConstructorOptions, type HTTPFetchBody, type HTTPFetchOptions, type HTTPOptions, httpProvider };