diff --git a/tower-http/Cargo.toml b/tower-http/Cargo.toml index 9aa3f07f..29d5d84b 100644 --- a/tower-http/Cargo.toml +++ b/tower-http/Cargo.toml @@ -89,7 +89,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", "dep:url", "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..c9c4dcbc 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`. @@ -410,8 +411,9 @@ where let future = self .try_call(req) .map(|result: Result<_, _>| -> Result<_, Infallible> { - let response = result.unwrap_or_else(|err| { - tracing::error!(error = %err, "Failed to read file"); + let response = result.unwrap_or_else(|_err| { + #[cfg(feature = "tracing")] + tracing::error!(error = %_err, "Failed to read file"); 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..0605b017 100644 --- a/tower-http/src/services/fs/serve_dir/open_file.rs +++ b/tower-http/src/services/fs/serve_dir/open_file.rs @@ -348,8 +348,10 @@ fn append_slash_on_path(uri: Uri) -> Result { uri_builder.path_and_query("/") }; - uri_builder.build().map_err(|err| { - tracing::error!(?err, "redirect uri failed to build"); + uri_builder.build().map_err(|_err| { + #[cfg(feature = "tracing")] + tracing::error!(?_err, "redirect uri failed to build"); + OpenFileOutput::InvalidRedirectUri }) }