ignore case on header keys
This commit is contained in:
parent
d2fb78108e
commit
fc064efb61
2 changed files with 6 additions and 7 deletions
|
@ -48,7 +48,7 @@ pub struct Request<'a> {
|
|||
path: &'a str,
|
||||
method: &'a str,
|
||||
version: &'a str,
|
||||
headers: HashMap<&'a str, &'a str>,
|
||||
headers: HashMap<String, &'a str>,
|
||||
query: HashMap<&'a str, &'a str>,
|
||||
body: Option<String>,
|
||||
real_address: IpAddr,
|
||||
|
@ -82,7 +82,7 @@ impl<'a> Request<'a> {
|
|||
None => {},
|
||||
}
|
||||
|
||||
let mut headers: HashMap<&'a str, &'a str> = HashMap::new();
|
||||
let mut headers: HashMap<String, &'a str> = HashMap::new();
|
||||
if lines.len() > 1 {
|
||||
let mut i: usize = 1;
|
||||
loop {
|
||||
|
@ -90,7 +90,7 @@ impl<'a> Request<'a> {
|
|||
let line = &lines[i];
|
||||
if line.len() == 0 || !line.contains(":") { break; }
|
||||
let (name, value) = line.split_once(":").unwrap();
|
||||
headers.insert(name, value.trim());
|
||||
headers.insert(name.to_lowercase(), value.trim());
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ impl<'a> Request<'a> {
|
|||
pub fn body(&self) -> &Option<String> {
|
||||
&self.body
|
||||
}
|
||||
pub fn headers(&self) -> &HashMap<&'a str, &'a str> {
|
||||
pub fn headers(&self) -> &HashMap<String, &'a str> {
|
||||
&self.headers
|
||||
}
|
||||
pub fn query(&self) -> &HashMap<&'a str, &'a str> {
|
||||
|
@ -282,7 +282,6 @@ impl HttpServer {
|
|||
Ok(status) => {
|
||||
let end_date = Local::now();
|
||||
|
||||
|
||||
println!(
|
||||
"[{}] {} {} {} - {} {} - {}ms - {} ({})",
|
||||
start_date.format("%Y-%m-%d %H:%M:%S"),
|
||||
|
|
|
@ -81,7 +81,7 @@ env!("CARGO_PKG_VERSION"));
|
|||
}
|
||||
|
||||
if request.path() == "/" {
|
||||
if request.headers().get("Accept").is_some_and(
|
||||
if request.headers().get("accept").is_some_and(
|
||||
|accept| accept.contains("text/html")
|
||||
) {
|
||||
// HTML response
|
||||
|
@ -136,7 +136,7 @@ env!("CARGO_PKG_VERSION"));
|
|||
|
||||
let response_content = content
|
||||
.replace("{{response}}", &query_response)
|
||||
.replace("{{host}}", match request.headers().get("Host") {
|
||||
.replace("{{host}}", match request.headers().get("host") {
|
||||
Some(host) => { host }
|
||||
None => { "mcq.bliss.town" }
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue