Remove serve_protocols option for now, it's not useful
This commit is contained in:
parent
63f4975d5a
commit
edadaab792
@ -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<SettingsServeProtocol> {
|
||||
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<SettingsServeProtocol>,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
@ -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");
|
||||
|
@ -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)
|
||||
|
@ -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<bool, D::Error>
|
||||
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<String>,
|
||||
|
||||
domain_setting_origin_descr_proxy_url: Option<String>,
|
||||
|
||||
#[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<FlatDomainSettings> for domain::Settings {
|
||||
@ -52,20 +31,7 @@ impl TryFrom<FlatDomainSettings> for domain::Settings {
|
||||
_ => Err("invalid domain_setting_origin_descr_kind".to_string()),
|
||||
}?;
|
||||
|
||||
let mut serve_protocols = Vec::<domain::SettingsServeProtocol>::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<domain::Settings> 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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user