XForwardedMiddleware#
- class safir.middleware.x_forwarded.XForwardedMiddleware(app, *, proxies=None)#
- Bases: - object- ASGI middleware to update the request based on - X-Forwarded-For.- The remote IP address will be replaced with the right-most IP address in - X-Forwarded-Forthat is not contained within one of the trusted proxy networks.- If - X-Forwarded-Foris found and- X-Forwarded-Protois also present, the corresponding entry of- X-Forwarded-Protois used to replace the scheme in the request scope. If- X-Forwarded-Protoonly has one entry (ingress-nginx has this behavior), that one entry will become the new scheme in the request scope.- The contents of - X-Forwarded-Hostwill be stored as- forwarded_hostin the request state if it and- X-Forwarded-Forare present. Normally this is not needed since NGINX will pass the original- Hostheader without modification.- Parameters:
- proxies ( - list[- _BaseNetwork] |- None, default:- None) – The networks of the trusted proxies. If not specified, defaults to the empty list, which means only the immediately upstream proxy will be trusted.
- app ( - Callable[[- MutableMapping[- str,- Any],- Callable[[],- Awaitable[- MutableMapping[- str,- Any]]],- Callable[[- MutableMapping[- str,- Any]],- Awaitable[- None]]],- Awaitable[- None]])
 
 - Methods Summary - __call__(scope, receive, send)- Call self as a function. - Methods Documentation