1
0
Fork 0
mirror of https://github.com/redlib-org/redlib.git synced 2025-04-05 14:07:39 +03:00

Support HEAD requests

This commit is contained in:
Kot 2025-01-27 18:25:59 -06:00
parent d7ec07cd0d
commit b09e948423
No known key found for this signature in database

View file

@ -240,8 +240,14 @@ impl Server {
path.pop();
}
// Replace HEAD with GET for routing
let (method, is_head) = match req.method() {
&Method::HEAD => (&Method::GET, true),
method => (method, false),
};
// Match the visited path with an added route
match router.recognize(&format!("/{}{}", req.method().as_str(), path)) {
match router.recognize(&format!("/{}{}", method.as_str(), path)) {
// If a route was configured for this path
Ok(found) => {
let mut parammed = req;
@ -253,7 +259,11 @@ impl Server {
match func.await {
Ok(mut res) => {
res.headers_mut().extend(def_headers);
let _ = compress_response(&req_headers, &mut res).await;
if is_head {
*res.body_mut() = Body::empty();
} else {
let _ = compress_response(&req_headers, &mut res).await;
}
Ok(res)
}