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)Get X-Forwarded-Proto values. 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: CIMultiDictProxy) → List[str]¶ Get X-Forwarded-Proto values.
This replaces the base class version to remove the exception when multiple
X-Forwarded-Protoheaders are present. This is a workaround for a bug in version 1.39.1 of the Kubernetes NGINX ingress. See https://github.com/kubernetes/ingress-nginx/issues/5670.Parameters: headers ( multidict.CIMultiDictProxy) – The headers of the request.Returns: forwarded_proto – A list of schemes from the X-Forwarded-Protoheader.Return type: List[ str]
-
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)¶
-