Skip to main content

validate_affinity_key

Function validate_affinity_key 

Source
pub fn validate_affinity_key(
    affinity_header: Option<&str>,
    affinity_cookie: Option<&str>,
) -> Result<(), &'static str>
Expand description

Validate a cluster’s client affinity key source, affinity_header or affinity_cookie.

At most one of the two may be set, and the one that is must be an RFC 9110 token (a cookie name is a token too, RFC 6265 §4.1.1): a name no request can carry would silently key every request on its source IP.

Two header names are refused although they are tokens, because the key lookup can never find them among the request’s headers: Host, which the H1 parser folds into the request authority and elides (H2 carries it as :authority), and Cookie, whose crumbs both parsers move into the cookie jar — key on one cookie with affinity_cookie instead. Names compare case-insensitively, as header names do.

Called on every AddCluster, so a TOML load, a reload, a saved state and a direct API request are held to the same rule as sozu cluster add.