Skip to main content

tiny_proxy/config/
models.rs

1use std::collections::HashMap;
2
3#[cfg(feature = "api")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone)]
7#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
8pub struct Config {
9    pub sites: HashMap<String, SiteConfig>,
10}
11
12#[derive(Debug, Clone)]
13#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
14pub struct SiteConfig {
15    pub address: String,
16    pub directives: Vec<Directive>,
17    /// TLS configuration for this site. When present, the site listens as HTTPS.
18    #[cfg_attr(feature = "api", serde(skip_serializing_if = "Option::is_none"))]
19    pub tls: Option<TlsConfig>,
20}
21
22/// TLS configuration for a site — paths to certificate chain and private key.
23#[derive(Debug, Clone)]
24#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
25pub struct TlsConfig {
26    pub cert_path: String,
27    pub key_path: String,
28}
29
30#[derive(Debug, Clone)]
31#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
32pub enum Directive {
33    ReverseProxy {
34        to: String,
35        connect_timeout: Option<u64>,
36        read_timeout: Option<u64>,
37        #[cfg_attr(feature = "api", serde(default))]
38        header_up: Vec<HeaderDirective>,
39    },
40    HandlePath {
41        pattern: String,
42        directives: Vec<Directive>,
43    },
44    UriReplace {
45        find: String,
46        replace: String,
47    },
48    Header {
49        name: String,
50        value: Option<String>,
51    },
52    Method {
53        methods: Vec<String>,
54        directives: Vec<Directive>,
55    },
56    StripPrefix {
57        prefix: String,
58    },
59    Redirect {
60        status: u16,
61        url: String,
62    },
63    Respond {
64        status: u16,
65        body: String,
66    },
67}
68
69/// A single header operation within a `header_up` block.
70/// `value = None` means the header should be removed.
71#[derive(Debug, Clone)]
72#[cfg_attr(feature = "api", derive(Serialize, Deserialize))]
73pub struct HeaderDirective {
74    pub name: String,
75    pub value: Option<String>,
76}