diff --git a/Cargo.lock b/Cargo.lock index 12d2468..76ca06a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,6 +446,7 @@ dependencies = [ "dirs", "handlebars", "hex", + "http", "rand 0.7.3", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index e981072..eeb16b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/server.rs b/src/server.rs index 493b134..b5915f4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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::>(), ); 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", ) diff --git a/src/utils.rs b/src/utils.rs index 91e1c56..681d038 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -39,3 +39,10 @@ pub fn format_pubkey(raw: &str) -> Result { &checksum[..3] )) } + +pub fn redirect_302(url: &str) -> warp::reply::WithStatus> { + warp::reply::with_status( + warp::reply::with_header("", "Location", url), + http::status::StatusCode::FOUND, + ) +}