basic router, define URI pattern

This commit is contained in:
Quentin 2024-02-27 00:12:01 +01:00
parent 3d3fd80629
commit ea32a813a7
Signed by: quentin
GPG key ID: E9602264D639FF68

View file

@ -67,8 +67,13 @@ impl Server {
}
async fn router(req: Request<impl hyper::body::Body>) -> Result<Response<Full<Bytes>>> {
let url_exploded: Vec<_> = req.uri().path().split(",").collect();
match url_exploded {
let path_segments: Vec<_> = req.uri().path().split("/").filter(|s| *s != "").collect();
match path_segments.as_slice() {
[] => tracing::info!("root"),
[ user ] => tracing::info!(user=user, "user home"),
[ user, coltype ] => tracing::info!(user=user, cat=coltype, "user cat of coll"),
[ user, coltype, colname ] => tracing::info!(user=user, cat=coltype, name=colname, "user coll"),
[ user, coltype, colname, member ] => tracing::info!(user=user, cat=coltype, name=colname, obj=member, "accessing file"),
_ => unimplemented!(),
}
Ok(Response::new(Full::new(Bytes::from("Hello World!"))))