Skip to content

Commit a21fb7c

Browse files
committed
upgrade tower-http, remove workaround
This includes tower-rs/tower-http#331
1 parent 8e5b4b2 commit a21fb7c

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

Cargo.lock

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ axum-extra = "0.5.0"
9090
hyper = { version = "0.14.15", default-features = false }
9191
tower = "0.4.11"
9292
tower-service = "0.3.2"
93-
tower-http = { version = "0.3.4", features = ["fs", "trace"] }
93+
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
9494
mime = "0.3.16"
9595
percent-encoding = "2.2.0"
9696

src/web/statics.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{cache::CachePolicy, error::AxumNope, metrics::request_recorder, routes::get_static};
1+
use super::{cache::CachePolicy, metrics::request_recorder, routes::get_static};
22
use axum::{
33
extract::Extension,
44
headers::HeaderValue,
@@ -9,7 +9,6 @@ use axum::{
99
routing::get_service,
1010
Router as AxumRouter,
1111
};
12-
use std::io;
1312
use tower_http::services::ServeDir;
1413

1514
const VENDORED_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/vendored.css"));
@@ -18,19 +17,6 @@ const RUSTDOC_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc.css"))
1817
const RUSTDOC_2021_12_05_CSS: &str =
1918
include_str!(concat!(env!("OUT_DIR"), "/rustdoc-2021-12-05.css"));
2019

21-
/// handle io-errors while serving static files.
22-
///
23-
/// Some errors can directly converted into a `404 NOT FOUND`,
24-
/// the rest will lead to a server error.
25-
async fn handle_error(err: io::Error) -> impl IntoResponse {
26-
match err.raw_os_error() {
27-
// ENOTDIR -> "not a directory
28-
Some(20) => AxumNope::ResourceNotFound,
29-
// fallback: raise a server error
30-
_ => AxumNope::InternalError(err.into()),
31-
}
32-
}
33-
3420
fn build_static_css_response(content: &'static str) -> impl IntoResponse {
3521
(
3622
Extension(CachePolicy::ForeverInCdnAndBrowser),
@@ -83,7 +69,6 @@ pub(crate) fn build_static_router() -> AxumRouter {
8369
.nest_service(
8470
"/",
8571
get_service(ServeDir::new("static").fallback(ServeDir::new("vendor")))
86-
.handle_error(handle_error)
8772
.layer(middleware::from_fn(set_needed_static_headers))
8873
.layer(middleware::from_fn(|request, next| async {
8974
request_recorder(request, next, Some("static resource")).await

0 commit comments

Comments
 (0)