1
- use super :: { cache:: CachePolicy , error :: AxumNope , metrics:: request_recorder, routes:: get_static} ;
1
+ use super :: { cache:: CachePolicy , metrics:: request_recorder, routes:: get_static} ;
2
2
use axum:: {
3
3
extract:: Extension ,
4
4
headers:: HeaderValue ,
@@ -9,7 +9,6 @@ use axum::{
9
9
routing:: get_service,
10
10
Router as AxumRouter ,
11
11
} ;
12
- use std:: io;
13
12
use tower_http:: services:: ServeDir ;
14
13
15
14
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"))
18
17
const RUSTDOC_2021_12_05_CSS : & str =
19
18
include_str ! ( concat!( env!( "OUT_DIR" ) , "/rustdoc-2021-12-05.css" ) ) ;
20
19
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
-
34
20
fn build_static_css_response ( content : & ' static str ) -> impl IntoResponse {
35
21
(
36
22
Extension ( CachePolicy :: ForeverInCdnAndBrowser ) ,
@@ -83,7 +69,6 @@ pub(crate) fn build_static_router() -> AxumRouter {
83
69
. nest_service (
84
70
"/" ,
85
71
get_service ( ServeDir :: new ( "static" ) . fallback ( ServeDir :: new ( "vendor" ) ) )
86
- . handle_error ( handle_error)
87
72
. layer ( middleware:: from_fn ( set_needed_static_headers) )
88
73
. layer ( middleware:: from_fn ( |request, next| async {
89
74
request_recorder ( request, next, Some ( "static resource" ) ) . await
0 commit comments