@@ -4,15 +4,17 @@ mod http_utils;
44mod query_params;
55mod scoped_file_system;
66
7+ use bytes:: Bytes ;
78use chrono:: { DateTime , Local } ;
89
910pub use file:: File ;
10- use humansize:: { format_size, DECIMAL } ;
11+ use http_body_util:: Full ;
12+ use humansize:: { DECIMAL , format_size} ;
1113
1214pub use scoped_file_system:: { Entry , ScopedFileSystem } ;
1315
1416use anyhow:: { Context , Result } ;
15- use handlebars:: { handlebars_helper , Handlebars } ;
17+ use handlebars:: { Handlebars , handlebars_helper } ;
1618use http:: response:: Builder as HttpResponseBuilder ;
1719use http:: { StatusCode , Uri } ;
1820use hyper:: Response ;
@@ -23,10 +25,11 @@ use std::path::{Component, Path, PathBuf};
2325use std:: str:: FromStr ;
2426use std:: sync:: Arc ;
2527
26- use crate :: handler:: file_server:: utils:: url_encode:: { decode_uri, encode_uri, PERCENT_ENCODE_SET } ;
28+ use crate :: handler:: file_server:: utils:: url_encode:: { PERCENT_ENCODE_SET , decode_uri, encode_uri} ;
29+ use crate :: server:: HttpResponse ;
2730
2831use self :: directory_entry:: { BreadcrumbItem , DirectoryEntry , DirectoryIndex , Sort } ;
29- use self :: http_utils:: { make_http_file_response , CacheControlDirective } ;
32+ use self :: http_utils:: { CacheControlDirective , make_http_file_response } ;
3033use self :: query_params:: { QueryParams , SortBy } ;
3134
3235/// Explorer's Handlebars template filename
@@ -136,7 +139,7 @@ impl<'a> FileServer {
136139 ///
137140 /// If the matched path resolves to a file, attempts to render it if the
138141 /// MIME type is supported, otherwise returns the binary (downloadable file)
139- pub async fn resolve ( & self , req_path : String ) -> Result < Response < Body > > {
142+ pub async fn resolve ( & self , req_path : String ) -> Result < HttpResponse > {
140143 let ( path, query_params) = FileServer :: parse_path ( req_path. as_str ( ) ) ?;
141144
142145 match self . scoped_file_system . resolve ( path) . await {
@@ -202,12 +205,12 @@ impl<'a> FileServer {
202205 let response = hyper:: Response :: builder ( )
203206 . status ( status)
204207 . header ( http:: header:: CONTENT_TYPE , "text/html" )
205- . body ( hyper :: Body :: from (
208+ . body ( Full :: new ( Bytes :: from (
206209 handlebars:: Handlebars :: new ( ) . render_template (
207210 include_str ! ( "./template/error.hbs" ) ,
208211 & serde_json:: json!( { "error" : err. to_string( ) , "code" : code} ) ,
209212 ) ?,
210- ) ) ?;
213+ ) ) ) ?;
211214
212215 Ok ( response)
213216 }
@@ -221,15 +224,15 @@ impl<'a> FileServer {
221224 & self ,
222225 path : PathBuf ,
223226 query_params : Option < QueryParams > ,
224- ) -> Result < Response < Body > > {
227+ ) -> Result < HttpResponse > {
225228 let directory_index =
226229 FileServer :: index_directory ( self . config . root_dir . clone ( ) , path, query_params) ?;
227230 let html = self
228231 . handlebars
229232 . render ( EXPLORER_TEMPLATE , & directory_index)
230233 . unwrap ( ) ;
231234
232- let body = Body :: from ( html) ;
235+ let body = Full :: new ( Bytes :: from ( html. as_bytes ( ) . to_vec ( ) ) ) ;
233236
234237 Ok ( HttpResponseBuilder :: new ( )
235238 . header ( http:: header:: CONTENT_TYPE , "text/html" )
0 commit comments