diff options
author | alyx <alyx@aleteoryx.me> | 2024-04-03 11:49:07 -0400 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2024-04-03 11:49:07 -0400 |
commit | d69f7fc08c491817358d944ab8177152d3afea19 (patch) | |
tree | 332a665d7204b1c56f69b8499a0f5fffd1db62bc | |
parent | 94ecd2bba5fb5207d7ea241a8b5762bc2e1376f9 (diff) | |
download | lfm_embed-d69f7fc08c491817358d944ab8177152d3afea19.tar.gz lfm_embed-d69f7fc08c491817358d944ab8177152d3afea19.tar.bz2 lfm_embed-d69f7fc08c491817358d944ab8177152d3afea19.zip |
Use http::Response for constructing replies
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 25 |
2 files changed, 15 insertions, 11 deletions
@@ -14,6 +14,7 @@ dotenv = "0.15.0" duration-str = "0.5.1" env_logger = "0.10.0" handlebars = { version = "4.3.7", features = ["dir_source"] } +http = "0.2.9" log = "0.4.19" reqwest = { version = "0.11.18", features = ["gzip", "deflate", "brotli", "json"] } serde = { version = "1.0.183", features = ["derive", "rc", "alloc"] } diff --git a/src/main.rs b/src/main.rs index 6669791..e3ac9eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,20 +51,23 @@ async fn main() { let (theme, res) = lfm_embed::theming::render_theme(q.theme.as_deref(), &data); log::debug!(target: "lfm_embed::server::user", "Using theme {theme}"); + match res { Err(status) => - Box::new(warp::reply::with_status(warp::reply::html("<h1>Internal Server Error.</h1>"), status)) - as Box<dyn warp::reply::Reply>, + http::Response::builder() + .status(status) + .header("Content-Type", "text/html") + .body("<h1>Internal Server Error.</h1><p>Occurred when templating, check the logs.</p>".into()) + .unwrap(), + Ok(contents) => - Box::new(warp::reply::with_header( - warp::reply::with_header( - warp::reply::with_status( - warp::reply::html( - contents - ), status - ), "Refresh", dur.as_secs() - ), "X-Selected-Theme", theme - )) as Box<dyn warp::reply::Reply> + http::Response::builder() + .status(status) + .header("Refresh", dur.as_secs()) + .header("X-Selected-Theme", theme) + .header("Content-Type", "text/html") + .body(contents) + .unwrap() } }); |