remove protocol settings
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s

This commit is contained in:
Neshura 2024-04-08 23:05:33 +02:00
parent 0b1ada9221
commit 8e077609e9
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -36,25 +36,9 @@ macro_rules! error {
};
}
#[derive(Clone, Serialize, Deserialize)]
enum Protocol {
Http,
Https
}
impl Display for Protocol {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Protocol::Http => write!(f, "http://"),
Protocol::Https => write!(f, "https://")
}
}
}
#[derive(Clone, Serialize, Deserialize)]
struct DomainLinkConfig {
domains: Vec<String>,
protocol: Protocol,
target: String,
}
@ -196,7 +180,7 @@ async fn handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpReques
println!("{host}");
for redirect in redirects.iter() {
if redirect.domains.contains(&host.to_owned()) {
return HttpResponse::PermanentRedirect().insert_header(("location", format!("{}{}", redirect.protocol, redirect.target).as_str())).finish();
return HttpResponse::PermanentRedirect().insert_header(("location", redirect.target.to_string().as_str())).finish();
}
}
let fail_msg = format!("No Redirect for {host} found");
@ -212,7 +196,7 @@ async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRe
println!("{host}");
for redirect in redirects.iter() {
if redirect.domains.contains(&host.to_owned()) {
let body = format!("Redirecting: {} -> {}{}", host, redirect.protocol, redirect.target);
let body = format!("Redirecting: {} -> {}", host, redirect.target);
return HttpResponse::Ok().body(body);
}
}