readClient static method
The client ip and scheme of req. trusted is the
trustedProxies setting. It is parsed once per isolate.
Implementation
static ({String? ip, String scheme}) readClient(
HttpRequest req,
List<String> trusted,
) {
if (!identical(trusted, _cachedList)) {
_cached = TrustedProxy(trusted);
_cachedList = trusted;
}
String? address = req.connectionInfo?.remoteAddress.address;
String? remote = address == null ? null : normalize(address);
if (remote == null || !_cached.enabled) return (ip: remote, scheme: 'http');
return (
ip: _cached.clientIp(remote, req.headers.value('x-forwarded-for')),
scheme: _cached.scheme(remote, req.headers.value('x-forwarded-proto')),
);
}