Skip to content

Commit

Permalink
fix: errors due to "unused code" when features are disabled (#368)
Browse files Browse the repository at this point in the history
* Fix errors due to "unused code" when features are disabled 

* Do not merge crate imports

* Rearrange code to make silencing clippy unnecessary

* Removed unnecessary newline

---------

Co-authored-by: Jose Quintana <1700322+joseluisq@users.noreply.github.com>
  • Loading branch information
palant and joseluisq committed Apr 27, 2024
1 parent 5a4035f commit c8e39aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
//! Request handler module intended to manage incoming HTTP requests.
//!

#[cfg(any(
feature = "compression",
feature = "compression-gzip",
feature = "compression-brotli",
feature = "compression-zstd",
feature = "compression-deflate"
))]
use headers::HeaderValue;
use hyper::{Body, Request, Response, StatusCode};
use std::{future::Future, net::IpAddr, net::SocketAddr, path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -273,27 +280,25 @@ impl RequestHandler {
{
Ok(result) => (result.resp, result.is_precompressed, Some(result.file_path)),
Err(status) => {
let mut resp = None;
// Produce an error response by default
let resp = error_page::error_response(
req.uri(),
req.method(),
&status,
&self.opts.page404,
&self.opts.page50x,
)?;

// Check for a fallback response
#[cfg(feature = "fallback-page")]
if req.method().is_get()
let resp = if req.method().is_get()
&& status == StatusCode::NOT_FOUND
&& !self.opts.page_fallback.is_empty()
{
resp = Some(fallback_page::fallback_response(&self.opts.page_fallback));
}

let resp = resp.unwrap_or(
// Otherwise return an error response
error_page::error_response(
req.uri(),
req.method(),
&status,
&self.opts.page404,
&self.opts.page50x,
)?,
);
fallback_page::fallback_response(&self.opts.page_fallback)
} else {
resp
};

(resp, false, None)
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ pub(crate) mod file_path;
pub(crate) mod file_response;
pub(crate) mod file_stream;
pub mod handler;
#[cfg(any(
feature = "compression",
feature = "compression-gzip",
feature = "compression-brotli",
feature = "compression-zstd",
feature = "compression-deflate"
))]
pub(crate) mod headers_ext;
pub(crate) mod health;
pub(crate) mod http_ext;
Expand Down

0 comments on commit c8e39aa

Please sign in to comment.