Path: redb-route/redb.Route.Cache/CacheHeaderPolicy.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Cache/CacheHeaderPolicy.cs ---- using redb.Route.Abstractions; namespace redb.Route.Cache; /// /// Which headers a cache entry may carry. A hit hands one exchange's headers to another, so an entry /// keeps what the miss produced, never what the exchange came in with, and never a credential: an /// Authorization, Proxy-Authorization (RFC 9110), Cookie or Set-Cookie /// (RFC 6265) belongs to the exchange it arrived on. The HTTP consumer drops Authorization after /// its own check for the same reason; the cache is the other place a header crosses exchanges. /// internal static class CacheHeaderPolicy { private static readonly HashSet Credentials = new(StringComparer.OrdinalIgnoreCase) { "Authorization", "Proxy-Authorization", "Cookie", "Set-Cookie", }; /// A header a cache entry never carries, whichever form named it. public static bool IsCredential(string name) => Credentials.Contains(name); /// The header values an exchange came in with, by name, taken before the inner steps run. public static Dictionary Snapshot(IMessage message) => new(message.Headers, StringComparer.OrdinalIgnoreCase); /// /// The headers of the inner steps produced: added, or set to another /// instance than the one in . A header the steps did not touch is the same /// instance afterwards, which is how the HTTP consumer tells a route's response header from an /// echoed request header. Credentials and cache.hit are never part of it. /// public static Dictionary Produced(IMessage message, IReadOnlyDictionary before) { var produced = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var (name, value) in message.Headers) { if (IsCredential(name) || string.Equals(name, CacheScopeProcessor.HitHeader, StringComparison.OrdinalIgnoreCase)) continue; if (before.TryGetValue(name, out var arrived) && ReferenceEquals(arrived, value)) continue; produced[name] = value; } return produced; } /// The names in the inner steps removed from . public static List Removed(IMessage message, IReadOnlyDictionary before) { var removed = new List(); foreach (var name in before.Keys) if (!message.Headers.ContainsKey(name)) removed.Add(name); return removed; } }