From 9d153ad907fb0d1f0e1780e90857c2cc5db729d5 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 27 May 2023 18:16:46 -0400 Subject: [PATCH] feat(server): allow configuring the content type for landing page (#48) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow user configuration of content type * style(format): apply formatting --------- Co-authored-by: Orhun Parmaksız --- config.toml | 1 + fixtures/test-server-landing-page/config.toml | 1 + shuttle/config.toml | 1 + src/config.rs | 2 ++ src/server.rs | 7 ++++++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index a4314a5..42d0687 100644 --- a/config.toml +++ b/config.toml @@ -31,6 +31,7 @@ changed this. Check out the GitHub repository at https://github.com/orhun/rustypaste Command line tool is available at https://github.com/orhun/rustypaste-cli """ +landing_page_content_type = "text/plain; charset=utf-8" [paste] random_url = { enabled = true, type = "petname", words = 2, separator = "-" } diff --git a/fixtures/test-server-landing-page/config.toml b/fixtures/test-server-landing-page/config.toml index 6f3be4b..2cd51c5 100644 --- a/fixtures/test-server-landing-page/config.toml +++ b/fixtures/test-server-landing-page/config.toml @@ -3,6 +3,7 @@ address="127.0.0.1:8000" max_content_length="10MB" upload_path="./upload" landing_page="awesome_landing" +landing_page_content_type = "text/plain; charset=utf-8" [paste] random_url = { enabled = false, type = "petname", words = 2, separator = "-" } diff --git a/shuttle/config.toml b/shuttle/config.toml index 90c41da..91f13bc 100644 --- a/shuttle/config.toml +++ b/shuttle/config.toml @@ -29,6 +29,7 @@ If you liked this, consider supporting me: https://donate.orhun.dev <3 🦀 """ +landing_page_content_type = "text/plain; charset=utf-8" [paste] # random_url = { enabled = true, type = "petname", words = 2, separator = "-" } diff --git a/src/config.rs b/src/config.rs index 6bad254..659762b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,6 +45,8 @@ pub struct ServerConfig { pub auth_token: Option, /// Landing page text. pub landing_page: Option, + /// Landing page content-type + pub landing_page_content_type: Option, /// Expose version. pub expose_version: Option, } diff --git a/src/server.rs b/src/server.rs index 6d2f0b7..9acd355 100644 --- a/src/server.rs +++ b/src/server.rs @@ -24,9 +24,14 @@ async fn index(config: web::Data>) -> Result let config = config .read() .map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?; + let content_type = config + .server + .landing_page_content_type + .clone() + .unwrap_or("text/plain; charset=utf-8".to_string()); match &config.server.landing_page { Some(page) => Ok(HttpResponse::Ok() - .content_type("text/plain; charset=\"UTF-8\"") + .content_type(content_type) .body(page.clone())), None => Ok(HttpResponse::Found() .append_header(("Location", env!("CARGO_PKG_HOMEPAGE")))