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; }