Skip to content

Commit 8b32e20

Browse files
authored
feat(core): add support for HEAD method in route handling (#260)
* feat(core): add support for HEAD and OPTIONS methods in route handling * refactor: remove redundant OPTIONS route insertion * refactor: simplify route addition logic for GET method * refactor: simplify http method comparison in route handling
1 parent 7b709c5 commit 8b32e20

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/shared/src/core/engine.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,18 @@ pub trait RouteInstance {
110110
/// * `path` - The path of the route.
111111
/// * `method` - The HTTP method of the route.
112112
/// * `handler` - The handler function for the route.
113-
fn add_route(&mut self, path: &str, method: Option<Method>, handler: RouteHandler) {
114-
let method = method
113+
fn add_route(&mut self, path: &str, http_method: Option<Method>, handler: RouteHandler) {
114+
if let Some(http_method) = &http_method {
115+
if http_method == Method::GET {
116+
self.router_mut()
117+
.insert(
118+
String::from("HEAD") + path,
119+
RouteHandler::Sync(Box::new(|_| Box::new(Bytes::default()))),
120+
)
121+
.unwrap_or_default();
122+
}
123+
}
124+
let method = http_method
115125
.map(|method| method.to_string())
116126
.unwrap_or_else(|| "{METHOD}".to_string());
117127

0 commit comments

Comments
 (0)