|
|
|
@ -186,15 +186,16 @@ fn handle(mut reader: BufReader<&mut TcpStream>) -> Result<Response, HandlingErr
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|(a, b)| a.to_lowercase() == "content-length")
|
|
|
|
|
{
|
|
|
|
|
let body: Vec<u8> = reader
|
|
|
|
|
.bytes()
|
|
|
|
|
.take(s.1.parse::<usize>().unwrap())
|
|
|
|
|
.collect::<Result<Vec<u8>, io::Error>>()
|
|
|
|
|
.unwrap();
|
|
|
|
|
// TODO test if it works
|
|
|
|
|
// FIXME deunwrap
|
|
|
|
|
// TODO handle body too large
|
|
|
|
|
request.add_body(body);
|
|
|
|
|
if request.method == Method::Post {
|
|
|
|
|
let body: Vec<u8> = reader
|
|
|
|
|
.bytes()
|
|
|
|
|
.take(s.1.parse::<usize>().unwrap())
|
|
|
|
|
.collect::<Result<Vec<u8>, io::Error>>()
|
|
|
|
|
.unwrap();
|
|
|
|
|
// FIXME deunwrap
|
|
|
|
|
// TODO handle body too large
|
|
|
|
|
request.add_body(body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dbg!(&request);
|
|
|
|
|
|
|
|
|
@ -220,14 +221,12 @@ fn get(path: &str) -> Result<Response, HandlingError> {
|
|
|
|
|
.fold(String::from(""), |a, b| format!("{a}\n{b}"));
|
|
|
|
|
let c = content("index", &ops);
|
|
|
|
|
|
|
|
|
|
Ok(Response::new(Status::Ok, vec![], c))
|
|
|
|
|
Ok(Response::new(Status::Ok, vec![], c.into()))
|
|
|
|
|
}
|
|
|
|
|
// TODO favicon.ico
|
|
|
|
|
"/css" => Ok(Response::new(Status::Ok, vec![], String::from(STYLE))),
|
|
|
|
|
|
|
|
|
|
"/faq" => Ok(Response::new(Status::Ok, vec![], String::from(FAQ))),
|
|
|
|
|
//"/favicon.ico" => Ok(Response::new(Status::Ok, vec![("content-type", "image/x-icon")], FAVICON)),
|
|
|
|
|
// TODO favicon
|
|
|
|
|
"/css" => Ok(Response::new(Status::Ok, vec![], String::from(STYLE).into())),
|
|
|
|
|
"/faq" => Ok(Response::new(Status::Ok, vec![], String::from(FAQ).into())),
|
|
|
|
|
"/favicon.ico" => Ok(Response::new(Status::Ok, vec![("content-type", "image/x-icon")], FAVICON.to_vec())),
|
|
|
|
|
|
|
|
|
|
// list specific thread here
|
|
|
|
|
// FIXME unwrap hell
|
|
|
|
@ -244,7 +243,7 @@ fn get(path: &str) -> Result<Response, HandlingError> {
|
|
|
|
|
.fold(String::from(""), |a, b| format!("{a}\n{b}"));
|
|
|
|
|
let c = content(&id.to_string(), &c);
|
|
|
|
|
|
|
|
|
|
Ok(Response::new(Status::Ok, vec![], c))
|
|
|
|
|
Ok(Response::new(Status::Ok, vec![], c.into()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -266,7 +265,7 @@ fn post(request: Request) -> Result<Response, HandlingError> {
|
|
|
|
|
Ok(Response::new(
|
|
|
|
|
Status::SeeOther,
|
|
|
|
|
vec![("location", "/")],
|
|
|
|
|
String::from(""),
|
|
|
|
|
vec![],
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -287,7 +286,7 @@ fn post(request: Request) -> Result<Response, HandlingError> {
|
|
|
|
|
Ok(Response::new(
|
|
|
|
|
Status::SeeOther,
|
|
|
|
|
vec![("location", s)],
|
|
|
|
|
String::from(""),
|
|
|
|
|
vec![],
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -335,7 +334,7 @@ fn main() {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// handle request
|
|
|
|
|
stream.write(response.to_string().as_bytes()).unwrap();
|
|
|
|
|
stream.write(&response.respond()).unwrap();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|