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