From 6798ff7533fbb000cef234ca9659e8d76b2f68f0 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Tue, 22 Nov 2022 20:41:11 +0100 Subject: [PATCH] refactor: reduce allocations when using fixed HTTP methods --- src/exts/http.rs | 2 +- src/static_files.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exts/http.rs b/src/exts/http.rs index 51274bc..1322d53 100644 --- a/src/exts/http.rs +++ b/src/exts/http.rs @@ -3,7 +3,7 @@ use hyper::Method; /// A fixed list of HTTP methods supported by SWS. -pub const HTTP_SUPPORTED_METHODS: [Method; 3] = [Method::OPTIONS, Method::HEAD, Method::GET]; +pub const HTTP_SUPPORTED_METHODS: &[Method; 3] = &[Method::OPTIONS, Method::HEAD, Method::GET]; /// SWS HTTP Method extensions trait. pub trait MethodExt { diff --git a/src/static_files.rs b/src/static_files.rs index ba217f7..19f6f89 100644 --- a/src/static_files.rs +++ b/src/static_files.rs @@ -94,7 +94,7 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response, bool), let mut resp = Response::new(Body::empty()); *resp.status_mut() = StatusCode::NO_CONTENT; resp.headers_mut() - .typed_insert(headers::Allow::from_iter(HTTP_SUPPORTED_METHODS)); + .typed_insert(headers::Allow::from_iter(HTTP_SUPPORTED_METHODS.clone())); resp.headers_mut().typed_insert(AcceptRanges::bytes()); return Ok((resp, is_precompressed)); -- libgit2 1.7.2