dvEffectiveHost function

String? dvEffectiveHost({
  1. required String? host,
  2. String? forwardedHost,
  3. required bool peerIsTrustedProxy,
})

The host a request was made for: X-Forwarded-Host when the peer is a proxy the application trusts (dartvel.server.trustedProxies, decided by DVClientAddress), the Host header otherwise. Of several forwarded entries the last is used: it is the one the trusted peer wrote, and anything to its left came from further away. Normalised by dvNormaliseHost.

Implementation

String? dvEffectiveHost({
  required String? host,
  String? forwardedHost,
  required bool peerIsTrustedProxy,
}) {
  if (peerIsTrustedProxy &&
      forwardedHost != null &&
      forwardedHost.trim().isNotEmpty) {
    final String last = forwardedHost.split(',').last;
    final String? forwarded = dvNormaliseHost(last);
    if (forwarded != null) return forwarded;
  }
  return dvNormaliseHost(host);
}