headersForHop function
The headers to carry to a redirect hop from from to to, before the
attestation headers are re-requested: as dart:io does, credentials and
cookies are dropped unless to is the same origin or a subdomain of it.
Implementation
Map<String, String> headersForHop(
Map<String, String> headers,
Uri from,
Uri to,
) {
if (_isSubdomain(to, from)) return Map.of(headers);
const dropped = {'authorization', 'www-authenticate', 'cookie', 'cookie2'};
return {
for (final entry in headers.entries)
if (!dropped.contains(entry.key.toLowerCase())) entry.key: entry.value,
};
}