Clear 302 redirects

This commit is contained in:
Pascal Engélibert 2020-12-08 22:39:02 +01:00
parent 51bd692392
commit 59c69765d7
4 changed files with 17 additions and 6 deletions

1
Cargo.lock generated
View File

@ -446,6 +446,7 @@ dependencies = [
"dirs",
"handlebars",
"hex",
"http",
"rand 0.7.3",
"serde",
"serde_json",

View File

@ -10,6 +10,7 @@ bs58 = "0.4.0"
dirs = "3.0.1"
handlebars = "3.5.1"
hex = "0.4.2"
http = "0.2"
rand = "0.7.3"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60"

View File

@ -77,6 +77,7 @@ pub async fn start_server(
)
.unwrap_or_else(|e| e.to_string()),
)
.into_response()
}
};
@ -92,6 +93,7 @@ pub async fn start_server(
)
.unwrap_or_else(|e| e.to_string()),
)
.into_response()
}
};
@ -111,6 +113,7 @@ pub async fn start_server(
)
.unwrap_or_else(|e| e.to_string()),
)
.into_response()
}
};
@ -162,7 +165,7 @@ pub async fn start_server(
.collect::<Vec<AdWithId>>(),
);
drop(cache_ads);
handle_index(&[])
redirect_302("/").into_response()
}
};
@ -217,12 +220,11 @@ pub async fn start_server(
}
}
}
handle_index(&[])
redirect_302("/").into_response()
}
};
let handle_admin_rm_ad = {
let handle_admin = handle_admin.clone();
move |query: AdminRmAdQuery| {
if let Ok(ad_id) = hex::decode(query.ad) {
if let Ok(ad_id) = AdId::try_from(ad_id.as_ref()) {
@ -244,7 +246,7 @@ pub async fn start_server(
}
}
}
handle_admin(&[])
redirect_302("/admin").into_response()
}
};
@ -303,7 +305,7 @@ pub async fn start_server(
move |query: AdminLoginQuery| {
if config.admin_passwords.contains(&query.psw) {
warp::reply::with_header(
warp::redirect(warp::http::Uri::from_static("/admin")),
redirect_302("/admin").into_response(),
"Set-Cookie",
format!(
"admin={}; path=/; HttpOnly",
@ -322,7 +324,7 @@ pub async fn start_server(
))
.or(warp::path("logout").and(warp::path::end()).map(|| {
warp::reply::with_header(
warp::redirect::temporary(warp::http::Uri::from_static("/")),
redirect_302("/").into_response(),
"Set-Cookie",
"admin=; HttpOnly; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT",
)

View File

@ -39,3 +39,10 @@ pub fn format_pubkey(raw: &str) -> Result<String, PubkeyDecodeError> {
&checksum[..3]
))
}
pub fn redirect_302(url: &str) -> warp::reply::WithStatus<warp::reply::WithHeader<&str>> {
warp::reply::with_status(
warp::reply::with_header("", "Location", url),
http::status::StatusCode::FOUND,
)
}