@@ -80,7 +80,7 @@ fn serve(req: Request) -> Result<Response> {
8080 // resolve the requested path and then try to read the file
8181 // None should indicate that the file does not exist after attempting fallback paths
8282 let body = match FileServer :: resolve ( path) {
83- Some ( path) => FileServer :: read ( path. as_str ( ) , & enc) . ok ( ) ,
83+ Some ( path) => FileServer :: read ( & path, & enc) . ok ( ) ,
8484 None => None ,
8585 } ;
8686
@@ -92,7 +92,7 @@ struct FileServer;
9292impl FileServer {
9393 /// Resolve the request path to a file path.
9494 /// Returns `None` if the path does not exist.
95- fn resolve ( req_path : & str ) -> Option < String > {
95+ fn resolve ( req_path : & str ) -> Option < PathBuf > {
9696 // fallback to index.html if the path is empty
9797 let mut path = if req_path. is_empty ( ) {
9898 PathBuf :: from ( DIRECTORY_FALLBACK_PATH )
@@ -114,15 +114,16 @@ impl FileServer {
114114
115115 // return the path if it exists
116116 if path. exists ( ) {
117- Some ( path. to_str ( ) . unwrap ( ) . to_string ( ) )
117+ Some ( path)
118118 } else {
119119 None
120120 }
121121 }
122122
123123 /// Open the file given its path and return its content and content type header.
124- fn read ( path : & str , encoding : & ContentEncoding ) -> Result < Bytes > {
125- let mut file = File :: open ( path) . with_context ( || anyhow ! ( "cannot open {}" , path) ) ?;
124+ fn read ( path : & PathBuf , encoding : & ContentEncoding ) -> Result < Bytes > {
125+ let mut file =
126+ File :: open ( path) . with_context ( || anyhow ! ( "cannot open {}" , path. display( ) ) ) ?;
126127 let mut buf = vec ! [ ] ;
127128 match encoding {
128129 ContentEncoding :: Brotli => {
0 commit comments