XForwardedFiltered¶
-
class
gafaelfawr.x_forwarded.XForwardedFiltered(trusted: Sequence[_BaseNetwork])¶ Bases:
aiohttp_remotes.x_forwarded.XForwardedBaseMiddleware to update the request based on
X-Forwarded-For.The semantics we want aren’t supported by either of the
aiohttp_remotesmiddleware classes, so we implement our own. This is similar toXForwardedRelaxedexcept that it takes the rightmost IP address that is not contained within one of the trusted networks.Parameters: trusted (Sequence[Union[ ipaddress.IPv4Network,ipaddress.IPv6Network]]) – List of trusted networks that should be skipped over when finding the actual client IP address.Methods Summary
get_forwarded_for(headers)get_forwarded_host(headers)get_forwarded_proto(headers)middleware(request, handler)Replace request information with details from proxy. raise_error(request)setup(app)Methods Documentation
-
get_forwarded_for(headers)¶
-
get_forwarded_host(headers)¶
-
get_forwarded_proto(headers)¶
-
middleware(request: web.Request, handler: Handler) → web.StreamResponse¶ Replace request information with details from proxy.
Honor
X-Forwarded-Forand related headers.Parameters: - request (
aiohttp.web.Request) – The aiohttp.web request. - handler (
typing.Callable) – The application’s request handler.
Returns: response – The response with a new
loggerkey attached to it.Return type: Notes
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 networks. The last entry ofX-Forwarded-Protoand the contents ofX-Forwarded-Hostwill be used unconditionally if they are present andX-Forwarded-Foris also present.- request (
-
raise_error(request)¶
-
setup(app)¶
-