diff --git a/Cargo.lock b/Cargo.lock index 712126f..bf37b92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -339,6 +339,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "case_insensitive_hashmap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ca1ed8675a76594ea5a5ad5cc318d72238cd4975d88f73768508fa577986b8" +dependencies = [ + "unicase", +] + [[package]] name = "cc" version = "1.1.7" @@ -1120,6 +1129,7 @@ name = "librespeed-rs" version = "1.3.6" dependencies = [ "ab_glyph", + "case_insensitive_hashmap", "chrono", "clap", "env_logger", @@ -2420,6 +2430,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + [[package]] name = "unicode-bidi" version = "0.3.15" diff --git a/Cargo.toml b/Cargo.toml index 58b87d0..df085df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ log = "0.4.22" indicatif = "0.17.9" #assets include_dir = "0.7.4" +case_insensitive_hashmap = "1.0.1" [package.metadata.deb] maintainer-scripts = "setup/debian/scripts/" diff --git a/src/http/request.rs b/src/http/request.rs index 1eb9a81..8775a51 100644 --- a/src/http/request.rs +++ b/src/http/request.rs @@ -3,6 +3,7 @@ use std::future::Future; use std::pin::Pin; use log::trace; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; +use case_insensitive_hashmap::CaseInsensitiveHashMap as CIHashMap; use crate::config::GARBAGE_DATA; use crate::http::{Method, MethodStr}; use crate::http::response::Response; @@ -13,7 +14,7 @@ pub struct Request { pub method: Method, pub remote_addr : String, pub query_params: HashMap, - pub headers: HashMap, + pub headers: CIHashMap, pub form_data : HashMap } @@ -189,11 +190,11 @@ fn hex_string_to_int(hex_string: &str) -> Option { } } -pub async fn header_parser(buf_reader: &mut BufReader) -> HashMap +pub async fn header_parser(buf_reader: &mut BufReader) -> CIHashMap where R: AsyncReadExt + Unpin { - let mut headers_out = HashMap::new(); + let mut headers_out = CIHashMap::new(); 'header_loop:loop { if let Ok(Some(header_line)) = buf_reader.lines().next_line().await { if header_line.is_empty() { @@ -211,7 +212,7 @@ where headers_out } -fn check_has_body(headers : &HashMap) -> (Option,Option) { +fn check_has_body(headers : &CIHashMap) -> (Option,Option) { let content_type_form = if let Some(content_type) = headers.get("Content-Type") { if content_type.starts_with("multipart/form-data;") { Some(BodyType::Form) @@ -279,7 +280,7 @@ fn clear_path_end_slash(input: &str) -> &str { } } -fn trust_addr_proxy(headers : &HashMap,remote_addr : &str) -> String { +fn trust_addr_proxy(headers : &CIHashMap,remote_addr : &str) -> String { if let Some(remote_ip) = headers.get("X-Real-IP") { remote_ip.to_string() } else {