apigate_core/routing/
header_sticky.rs1use crate::backend::BackendPool;
2
3use super::{AffinityKey, CandidateSet, RouteCtx, RouteStrategy, RoutingDecision};
4
5#[derive(Debug, Clone)]
6pub struct HeaderSticky {
7 header: &'static str,
8}
9
10impl HeaderSticky {
11 pub fn new(header: &'static str) -> Self {
12 Self { header }
13 }
14}
15
16impl RouteStrategy for HeaderSticky {
17 fn route<'a>(&self, ctx: &'_ RouteCtx, _pool: &'a BackendPool) -> RoutingDecision<'a> {
18 let affinity = ctx
19 .headers
20 .get(self.header)
21 .and_then(|v| v.to_str().ok())
22 .map(AffinityKey::owned);
23
24 RoutingDecision {
25 affinity,
26 candidates: CandidateSet::All,
27 }
28 }
29}