diff --git a/tower-http/Cargo.toml b/tower-http/Cargo.toml index 958007a4..cfd7f6a1 100644 --- a/tower-http/Cargo.toml +++ b/tower-http/Cargo.toml @@ -88,7 +88,7 @@ auth = ["base64", "validate-request"] catch-panic = ["tracing", "futures-util/std", "dep:http-body", "dep:http-body-util"] cors = [] follow-redirect = ["futures-util", "dep:http-body", "iri-string", "tower/util"] -fs = ["futures-core", "futures-util", "dep:http-body", "dep:http-body-util", "tokio/fs", "tokio-util/io", "tokio/io-util", "dep:http-range-header", "mime_guess", "mime", "percent-encoding", "httpdate", "set-status", "futures-util/alloc", "tracing"] +fs = ["futures-core", "futures-util", "dep:http-body", "dep:http-body-util", "tokio/fs", "tokio-util/io", "tokio/io-util", "dep:http-range-header", "mime_guess", "mime", "percent-encoding", "httpdate", "set-status", "futures-util/alloc"] limit = ["dep:http-body", "dep:http-body-util"] map-request-body = [] map-response-body = [] diff --git a/tower-http/src/services/fs/serve_dir/mod.rs b/tower-http/src/services/fs/serve_dir/mod.rs index 61b956d1..ea1fb583 100644 --- a/tower-http/src/services/fs/serve_dir/mod.rs +++ b/tower-http/src/services/fs/serve_dir/mod.rs @@ -255,7 +255,8 @@ impl ServeDir { /// By default `>::call` will handle IO errors and convert them into /// responses. It does that by converting [`std::io::ErrorKind::NotFound`] and /// [`std::io::ErrorKind::PermissionDenied`] to `404 Not Found` and any other error to `500 - /// Internal Server Error`. The error will also be logged with `tracing`. + /// Internal Server Error`. The error will also be logged with `tracing` in case the `tracing` + /// crate feature is enabled. /// /// If you want to manually control how the error response is generated you can make a new /// service that wraps a `ServeDir` and calls `try_call` instead of `call`. @@ -411,7 +412,10 @@ where .try_call(req) .map(|result: Result<_, _>| -> Result<_, Infallible> { let response = result.unwrap_or_else(|err| { + #[cfg(feature = "tracing")] tracing::error!(error = %err, "Failed to read file"); + #[cfg(not(feature = "tracing"))] + let _ = err; let body = ResponseBody::new(UnsyncBoxBody::new( Empty::new().map_err(|err| match err {}).boxed_unsync(), diff --git a/tower-http/src/services/fs/serve_dir/open_file.rs b/tower-http/src/services/fs/serve_dir/open_file.rs index 852b2ee3..b8233b61 100644 --- a/tower-http/src/services/fs/serve_dir/open_file.rs +++ b/tower-http/src/services/fs/serve_dir/open_file.rs @@ -349,7 +349,11 @@ fn append_slash_on_path(uri: Uri) -> Result { }; uri_builder.build().map_err(|err| { + #[cfg(feature = "tracing")] tracing::error!(?err, "redirect uri failed to build"); + #[cfg(not(feature = "tracing"))] + let _ = err; + OpenFileOutput::InvalidRedirectUri }) }