1+ import { Network } from "@cldn/ip" ;
12import EventEmitter from "node:events" ;
23import http from "node:http" ;
34import packageJson from "../package.json" with { type : "json" } ;
@@ -35,6 +36,10 @@ class Server<A> extends EventEmitter<Server.Events> {
3536 private readonly port ?: number ;
3637 private readonly copyOrigin : boolean ;
3738 private readonly handleConditionalRequests : boolean ;
39+ /**
40+ * The network of remote addresses of proxies to trust/
41+ */
42+ public readonly trustedProxies : Network ;
3843
3944 /**
4045 * Create a new HTTP server.
@@ -54,6 +59,7 @@ class Server<A> extends EventEmitter<Server.Events> {
5459 this . copyOrigin = options ?. copyOrigin ?? false ;
5560 this . handleConditionalRequests = options ?. handleConditionalRequests ?? true ;
5661 this . _authenticators = options ?. authenticators ?? [ ] ;
62+ this . trustedProxies = options ?. trustedProxies ?? new Network ( ) ;
5763
5864 if ( this . port !== undefined ) this . listen ( this . port ) . then ( ) ;
5965
@@ -237,6 +243,12 @@ namespace Server {
237243 * Authenticators for handling request authentication.
238244 */
239245 readonly authenticators ?: Authenticator < A > [ ] ;
246+
247+ /**
248+ * The network of trusted proxies. If specified, headers such as `Forwarded`, `X-Forwarded-For`, and `X-Real-IP`
249+ * will be trusted and automatically processed.
250+ */
251+ readonly trustedProxies ?: Network ;
240252 }
241253
242254 /**
0 commit comments