1use std::sync::Arc;
2
3use http::uri::PathAndQuery;
4
5use crate::PipelineFn;
6use crate::backend::BackendPool;
7use crate::policy::Policy;
8
9#[derive(Clone)]
10pub struct RouteMeta {
11 pub service: &'static str,
12 pub route_path: &'static str,
13 pub prefix: &'static str,
14 pub rewrite: Rewrite,
15 pub pool: Arc<BackendPool>,
16 pub policy: Arc<Policy>,
17 pub pipeline: Option<PipelineFn>,
18}
19
20#[derive(Clone, Debug)]
21pub enum Rewrite {
22 StripPrefix,
23 Static(FixedRewrite),
24 Template(&'static RewriteTemplate),
25}
26
27#[derive(Clone, Debug)]
28pub struct FixedRewrite {
29 raw: &'static str,
30 no_query: PathAndQuery,
31}
32
33impl FixedRewrite {
34 pub fn new(raw: &'static str) -> Self {
35 Self {
36 raw,
37 no_query: PathAndQuery::from_static(raw),
38 }
39 }
40
41 #[inline]
42 pub fn raw(&self) -> &'static str {
43 self.raw
44 }
45
46 #[inline]
47 pub fn no_query(&self) -> &PathAndQuery {
48 &self.no_query
49 }
50}
51
52#[derive(Debug, Clone, Copy)]
53pub struct RewriteTemplate {
54 pub src: &'static [SrcSeg],
55 pub dst: &'static [DstChunk],
56 pub static_len: usize,
57}
58
59#[derive(Debug, Clone, Copy)]
60pub enum SrcSeg {
61 Lit(&'static str),
62 Param,
63}
64
65#[derive(Debug, Clone, Copy)]
66pub enum DstChunk {
67 Lit(&'static str),
68 Capture { src_index: u8 },
69}
70
71#[derive(Clone, Copy, Debug)]
72pub enum RewriteSpec {
73 StripPrefix,
74 Static(&'static str),
75 Template(&'static RewriteTemplate),
76}