reifydb_network/utils/
mod.rs1use std::collections::HashMap;
5
6pub fn find_header_end(buf: &[u8]) -> Option<usize> {
7 let pattern = b"\r\n\r\n";
8 buf.windows(4).position(|w| w == pattern).map(|i| i + 4)
9}
10
11pub fn parse_headers(data: &[u8]) -> Result<HashMap<String, String>, String> {
12 let request_str = String::from_utf8_lossy(data);
13 let lines: Vec<&str> = request_str.lines().collect();
14
15 let mut headers = HashMap::new();
16 for line in lines.iter().skip(1) {
17 if line.is_empty() {
18 break;
19 }
20 if let Some(colon_pos) = line.find(':') {
21 let key = line[..colon_pos].trim().to_lowercase();
22 let value = line[colon_pos + 1..].trim().to_string();
23 headers.insert(key, value);
24 }
25 }
26
27 Ok(headers)
28}