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:
parent
d7ec07cd0d
commit
b09e948423
1 changed files with 12 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue