got rid of that fucking http crate for fags
parent
36f5eb943e
commit
a8b61ee96c
@ -0,0 +1,36 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
pub struct Request {
|
||||
pub method: String,
|
||||
pub uri: String,
|
||||
pub headers: Vec<(String, String)>,
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
// TODO implement this with display and enums
|
||||
impl FromStr for Request {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut iter = s.lines();
|
||||
let mut first = iter.nth(0).unwrap().split_whitespace();
|
||||
let method = first.next().unwrap().to_string();
|
||||
let uri = first.next().unwrap().to_string();
|
||||
let mut headers: Vec<(String, String)> = vec![];
|
||||
|
||||
for line in &mut iter {
|
||||
if line.is_empty() {
|
||||
break;
|
||||
}
|
||||
let line: Vec<&str> = line.split(":").take(2).collect();
|
||||
headers.push((line[0].into(), line[1].into()));
|
||||
}
|
||||
let body: String = iter.fold(String::new(), |a, b| format!("{}{}", a, b));
|
||||
|
||||
Ok(Self {
|
||||
method,
|
||||
uri,
|
||||
headers,
|
||||
body,
|
||||
})
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
use std::net::TcpListener;
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue