apigate_core/routing/
mod.rs1mod header_sticky;
2mod no_route_key;
3
4use std::borrow::Cow;
5
6use crate::backend::BackendPool;
7
8pub use header_sticky::HeaderSticky;
9pub use no_route_key::NoRouteKey;
10
11pub struct RouteCtx<'a> {
12 pub service: &'a str,
13 pub route_path: &'a str,
14 pub method: &'a http::Method,
15 pub uri: &'a http::Uri,
16 pub headers: &'a http::HeaderMap,
17}
18
19#[derive(Clone, Debug, Eq, PartialEq, Hash)]
20pub struct AffinityKey<'a>(Cow<'a, str>);
21
22impl<'a> AffinityKey<'a> {
23 pub fn borrowed(value: &'a str) -> Self {
24 Self(Cow::Borrowed(value))
25 }
26
27 pub fn owned(value: impl Into<String>) -> Self {
28 Self(Cow::Owned(value.into()))
29 }
30
31 pub fn as_str(&self) -> &str {
32 self.0.as_ref()
33 }
34
35 pub fn into_owned(self) -> String {
36 self.0.into_owned()
37 }
38}
39
40#[derive(Clone, Debug)]
41pub enum CandidateSet<'a> {
42 All,
43 Indices(&'a [usize]),
44}
45
46#[derive(Clone, Debug)]
47pub struct RoutingDecision<'a> {
48 pub affinity: Option<AffinityKey<'a>>,
49 pub candidates: CandidateSet<'a>,
50}
51
52pub trait RouteStrategy: Send + Sync + 'static {
53 fn route<'a>(&self, ctx: &'_ RouteCtx, pool: &'a BackendPool) -> RoutingDecision<'a>;
54}