Skip to main content

tiny_proxy/config/
models.rs

1use std::collections::HashMap;
2
3#[cfg(feature = "api")]
4use serde::{Deserialize, Serialize};
5
6// Models remain as same as we designed
7#[derive(Debug, Clone)]
8#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
9pub struct Config {
10    pub sites: HashMap<String, SiteConfig>,
11}
12
13#[derive(Debug, Clone)]
14#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
15pub struct SiteConfig {
16    pub address: String,
17    pub directives: Vec<Directive>,
18}
19
20#[derive(Debug, Clone)]
21#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
22pub enum Directive {
23    ReverseProxy {
24        to: String,
25        connect_timeout: Option<u64>,
26        read_timeout: Option<u64>,
27    },
28    HandlePath {
29        pattern: String,
30        directives: Vec<Directive>,
31    },
32    UriReplace {
33        find: String,
34        replace: String,
35    },
36    Header {
37        name: String,
38        value: Option<String>,
39    },
40    Method {
41        methods: Vec<String>,
42        directives: Vec<Directive>,
43    },
44    StripPrefix {
45        prefix: String,
46    },
47    Redirect {
48        status: u16,
49        url: String,
50    },
51    Respond {
52        status: u16,
53        body: String,
54    },
55}