index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2022-11-22 19:41:11.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2022-11-22 19:52:04.0 +00:00:00
commit
6798ff7533fbb000cef234ca9659e8d76b2f68f0 [patch]
tree
4addc2bcf2d35de2bd80a666783639200629cd04
parent
800416d91f0eddb3eecb365cb3ed291ed152258b
download
6798ff7533fbb000cef234ca9659e8d76b2f68f0.tar.gz

refactor: reduce allocations when using fixed HTTP methods



Diff

 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<Body>, 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));