From c20ab29d0b8e84da9575a62cf0d16813fdd4da1f Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Fri, 26 Apr 2024 00:07:14 +0100 Subject: [PATCH] add some stuff its been a while --- Cargo.toml | 2 +- src/main.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea823de..2640600 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "herb" version = "0.9.0-develop" -edition = "2018" +edition = "2021" [dependencies] frostwalker = "0.1.1" diff --git a/src/main.rs b/src/main.rs index ffe85d7..e1c4af6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ struct Settings { impl Settings { fn new() -> Settings { - return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string(), logging: false, server_header: true, time_header: false}; + return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string(), logging: false, server_header: false, time_header: false}; } } @@ -263,14 +263,14 @@ fn check_if_dir(directory: String) -> bool { return result; } -fn generate_index(directory: String) -> String { +fn generate_index(directory: String, ) -> String { let mut index = format!("

Directory of {}


Parent Directory
", directory, directory); for file in fs::read_dir(directory).unwrap() { index = format!("{}{}
", index, format!("\"/{}\"", file.as_ref().unwrap().path().display().to_string()), file.unwrap().file_name().into_string().unwrap_or("!!".to_string())); } - return format!("{}
Generated by herb/{}", index, env!("CARGO_PKG_VERSION")).to_string(); + return format!("{}
Generated by herb/{} ({})", index, env!("CARGO_PKG_VERSION"), std::env::consts::OS).to_string(); } @@ -553,9 +553,11 @@ fn serve(mut stream: TcpStream, settings: Settings) { let mut response_constructed = generate_response(resource.status_code, ""); response_constructed.headers.push(generate_kvheader("Content-Type", &resource.mime)); - response_constructed.headers.push(generate_kvheader("Server", &format!("herb/{}", env!("CARGO_PKG_VERSION")))); + if settings.server_header { + response_constructed.headers.push(generate_kvheader("Server", &format!("herb/{}", env!("CARGO_PKG_VERSION")))); + } - if cfg!(unix) { + if cfg!(unix) && settings.time_header { response_constructed.headers.push(generate_kvheader("Date", &grab_time())) } @@ -609,6 +611,13 @@ fn process_settings() -> Settings { settings.address = hashmap.get("address").unwrap_or(&"0.0.0.0:8080".to_string()).to_string(); } + if hashmap.get("time_header").is_some() { + settings.time_header = hashmap.get("time_header").unwrap_or(&"true".to_string()).parse::().unwrap_or(true); + } + + if hashmap.get("server_header").is_some() { + settings.server_header = hashmap.get("server_header").unwrap_or(&"true".to_string()).parse::().unwrap_or(true); + } return settings; }