@otterhttp/proxy-address
Version:
proxy-addr rewrite with TypeScript and ESM support
44 lines (41 loc) • 1.21 kB
TypeScript
import { IncomingMessage } from 'node:http';
import { IPv4, IPv6 } from 'ipaddr.js';
export { IPv4, IPv6 } from 'ipaddr.js';
type Req = Pick<IncomingMessage, "headers" | "socket">;
type TrustParameter = string | number | string[];
type TrustFunction = (addr: IPv4 | IPv6 | undefined, i: number) => boolean;
type Trust = TrustFunction | TrustParameter;
type Subnet = {
ip: IPv4 | IPv6;
range: number;
};
/**
* Get all addresses in the request, optionally stopping
* at the first untrusted.
*
* @param req
* @param trust
*/
declare function allAddresses(req: Req, trust?: Trust): Array<IPv4 | IPv6 | undefined>;
/**
* Compile argument into trust function.
*
* @param val
*/
declare function compile(val: string | number | string[]): TrustFunction;
/**
* Parse IP notation string into range subnet.
*
* @param {String} note
* @private
*/
declare function parseIPNotation(note: string): Subnet;
/**
* Determine address of proxied request.
*
* @param req
* @param trust
* @public
*/
declare function proxyAddress(req: Req, trust: Trust): IPv4 | IPv6 | undefined;
export { type Trust, type TrustFunction, type TrustParameter, allAddresses, compile, parseIPNotation, proxyAddress };