1- use super :: { cache:: CachePolicy , error :: AxumNope , metrics:: request_recorder, routes:: get_static} ;
1+ use super :: { cache:: CachePolicy , metrics:: request_recorder, routes:: get_static} ;
22use 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;
1312use tower_http:: services:: ServeDir ;
1413
1514const 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"))
1817const 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-
3420fn 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