Skip to main content

mcpr_core/proxy/
csp.rs

1/// CSP rewriting mode.
2#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
3pub enum CspMode {
4    /// Keep external domains from upstream, strip localhost, add configured extras + tunnel domain
5    #[default]
6    Extend,
7    /// Ignore upstream CSP entirely, use only configured domains + tunnel domain
8    Override,
9}
10
11impl std::fmt::Display for CspMode {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        match self {
14            CspMode::Extend => write!(f, "extend"),
15            CspMode::Override => write!(f, "override"),
16        }
17    }
18}
19
20pub fn parse_csp_mode(s: &str) -> CspMode {
21    match s.to_lowercase().as_str() {
22        "override" => CspMode::Override,
23        _ => CspMode::Extend,
24    }
25}