From ac3b98d72f59d37bb12431e12033b9b1e73ec20a Mon Sep 17 00:00:00 2001 From: int 80h Date: Mon, 8 Jun 2020 00:05:45 -0400 Subject: [PATCH] Add lang option --- Cargo.toml | 2 +- README | 3 ++- config.toml | 2 ++ src/config.rs | 1 + src/main.rs | 5 ++++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be657b5..dde0d8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gemserv" -version = "0.4.0" +version = "0.4.1" authors = ["int 80h "] edition = "2018" diff --git a/README b/README index abed8a9..a619bfe 100644 --- a/README +++ b/README @@ -16,7 +16,8 @@ A gemini server written in rust. OpenSSL 1.1.0g or LibreSSL 2.7.0 or newer is required. - Clone the repo - - Run 'cargo build --release' + - If you want to use all features run 'cargo build --release' or if you only + want to serve static files run 'cargo build --release --no-default-features' - Modify the config.toml to your needs - Run './target/release/gemserv config.toml' diff --git a/config.toml b/config.toml index e73bb42..7931657 100644 --- a/config.toml +++ b/config.toml @@ -17,6 +17,8 @@ cert = "/path/to/cert" # index is optional but defaults to index.gemini. The server will serve files # ending in gemini or gmi. index = "index.gmi" +# lang is optional +lang = "en" # cgi is optional bool cgi = true # cgipath is optional and only checked if cgi is true. It restricts cgi to only diff --git a/src/config.rs b/src/config.rs index 85cbd40..bbe9a28 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,7 @@ pub struct Server { pub key: String, pub cert: String, pub index: Option, + pub lang: Option, #[cfg(feature = "cgi")] pub cgi: Option, #[cfg(feature = "cgi")] diff --git a/src/main.rs b/src/main.rs index c8ce3aa..b458ba5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -296,7 +296,10 @@ async fn handle_connection( return Ok(()); } - let mime = get_mime(&path); + let mut mime = get_mime(&path); + if mime == "text/gemini" && srv.server.lang.is_some() { + mime += &("; lang=".to_string() + &srv.server.lang.to_owned().unwrap()); + } if !mime.starts_with("text/") { logger::logger(con.peer_addr, Status::Success, &request); get_binary(con, path, mime).await?;