diff --git a/src/domain/settings.rs b/src/domain/settings.rs index 6b6bb5a..791d95d 100644 --- a/src/domain/settings.rs +++ b/src/domain/settings.rs @@ -5,28 +5,12 @@ use hex::ToHex; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -#[serde(tag = "protocol")] -pub enum SettingsServeProtocol { - #[serde(rename = "http")] - Http, - #[serde(rename = "https")] - Https, -} - -fn default_serve_protocols() -> Vec { - vec![SettingsServeProtocol::Http, SettingsServeProtocol::Https] -} - #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] /// Defines how a domain will behave when it is accessed. These are configured by the owner of the /// domain during setup. pub struct Settings { #[serde(flatten)] pub origin_descr: origin::Descr, - - #[serde(default = "default_serve_protocols")] - pub serve_protocols: Vec, } impl Settings { diff --git a/src/domain/store.rs b/src/domain/store.rs index 1d6a191..efe3a68 100644 --- a/src/domain/store.rs +++ b/src/domain/store.rs @@ -181,7 +181,6 @@ mod tests { url: "bar".to_string(), branch_name: "baz".to_string(), }, - serve_protocols: vec![domain::SettingsServeProtocol::Http], }; assert!(matches!( @@ -204,7 +203,6 @@ mod tests { url: "BAR".to_string(), branch_name: "BAZ".to_string(), }, - serve_protocols: vec![], }; store.set(&domain, &new_settings).expect("set"); diff --git a/src/service/http.rs b/src/service/http.rs index 147325f..9e016df 100644 --- a/src/service/http.rs +++ b/src/service/http.rs @@ -177,18 +177,6 @@ impl<'svc> Service { } }; - let allowed = settings.serve_protocols.iter().any(|p| match p { - domain::SettingsServeProtocol::Http => !req_is_https, - domain::SettingsServeProtocol::Https => req_is_https, - }); - - if !allowed { - return self.render_error_page( - 421, - "The requested protocol is not supported by this domain", - ); - } - // if the domain is backed by a proxy then that is handled specially. if let origin::Descr::Proxy { .. } = settings.origin_descr { return origin::proxy::serve_http_request(&settings, client_ip, req, req_is_https) diff --git a/src/service/util.rs b/src/service/util.rs index 13fdd77..e4eec2f 100644 --- a/src/service/util.rs +++ b/src/service/util.rs @@ -1,22 +1,9 @@ use std::convert::TryFrom; -use serde::{de, Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::{domain, error::unexpected, origin}; -fn deserialize_bool<'de, D>(deserializer: D) -> Result -where - D: de::Deserializer<'de>, -{ - let s: &str = de::Deserialize::deserialize(deserializer)?; - - match s { - "true" => Ok(true), - "false" => Ok(false), - _ => Err(de::Error::unknown_variant(s, &["true", "false"])), - } -} - #[derive(Serialize, Deserialize, Default)] pub struct FlatDomainSettings { domain_setting_origin_descr_kind: String, @@ -25,14 +12,6 @@ pub struct FlatDomainSettings { domain_setting_origin_descr_git_branch_name: Option, domain_setting_origin_descr_proxy_url: Option, - - #[serde(default)] - #[serde(deserialize_with = "deserialize_bool")] - domain_setting_serve_protocol_http: bool, - - #[serde(default)] - #[serde(deserialize_with = "deserialize_bool")] - domain_setting_serve_protocol_https: bool, } impl TryFrom for domain::Settings { @@ -52,20 +31,7 @@ impl TryFrom for domain::Settings { _ => Err("invalid domain_setting_origin_descr_kind".to_string()), }?; - let mut serve_protocols = Vec::::default(); - - if v.domain_setting_serve_protocol_http { - serve_protocols.push(domain::SettingsServeProtocol::Http); - } - - if v.domain_setting_serve_protocol_https { - serve_protocols.push(domain::SettingsServeProtocol::Https); - } - - Ok(Self { - origin_descr, - serve_protocols, - }) + Ok(Self { origin_descr }) } } @@ -88,17 +54,6 @@ impl TryFrom for FlatDomainSettings { } } - for serve_protocol in v.serve_protocols { - match serve_protocol { - domain::SettingsServeProtocol::Http => { - res.domain_setting_serve_protocol_http = true - } - domain::SettingsServeProtocol::Https => { - res.domain_setting_serve_protocol_https = true - } - } - } - Ok(res) } }