@@ -135,10 +135,7 @@ async fn main() {
135135 . route ( "/v1/file" , post ( ax_post_file) )
136136 . route ( "/upload" , post ( ax_post_file) )
137137 . route ( "/*filepath" , get ( ax_get_file) )
138- . layer (
139- ServiceBuilder :: new ( )
140- . layer ( DefaultBodyLimit :: max ( 1024 * 1024 * 1024 * 4 ) ) ,
141- ) ;
138+ . layer ( ServiceBuilder :: new ( ) . layer ( DefaultBodyLimit :: max ( 1024 * 1024 * 1024 * 4 ) ) ) ;
142139
143140 /*
144141 .layer(SecureClientIpSource::ConnectInfo.into_extension())
@@ -292,16 +289,18 @@ async fn ax_get_file(
292289) -> impl IntoResponse {
293290 let timestamp = std:: time:: SystemTime :: now ( ) ;
294291 let human_time = chrono:: DateTime :: < chrono:: Utc > :: from ( timestamp) ;
295- // or none
296292 let user_agent = rxheaders. get ( "User-Agent" ) ;
297293 let user_agent_str = match user_agent {
298294 Some ( user_agent) => user_agent. to_str ( ) . unwrap ( ) ,
299295 None => "" ,
300296 } ;
301- // remote_addr human_time method filepath
302- println ! ( "{:?} {} {} {} {}" , remote_addr, human_time, method, filepath, user_agent_str) ;
297+
303298 let received_file = driver_get_file ( filepath. clone ( ) ) ;
304299 if !received_file. valid {
300+ println ! (
301+ "{:?} 404 0 {} {} {} {}" ,
302+ remote_addr, human_time, method, filepath, user_agent_str
303+ ) ;
305304 return ( StatusCode :: NOT_FOUND , format ! ( "Not Found: {}" , filepath) ) . into_response ( ) ;
306305 }
307306 let cached_file = received_file. cached_filename ;
@@ -325,7 +324,11 @@ async fn ax_get_file(
325324
326325 /* Usually HEAD is used to check if the file exists and range is supported */
327326 if method == axum:: http:: Method :: HEAD {
328- println ! ( "HEAD request, returning headers only" ) ;
327+ //println!("HEAD request, returning headers only");
328+ println ! (
329+ "{:?} 200 0 {} {} {} {}" ,
330+ remote_addr, human_time, method, filepath, user_agent_str
331+ ) ;
329332 return ( headers, Body :: empty ( ) ) . into_response ( ) ;
330333 }
331334 match tokio:: fs:: File :: open ( & cached_file) . await {
@@ -370,14 +373,32 @@ async fn ax_get_file(
370373 let stream = ReaderStream :: new ( file) ;
371374 let axbody = Body :: from_stream ( stream) ;
372375
373- println ! ( "Headers: {:?}" , headers) ;
376+ // println!("Headers: {:?}", headers);
374377 if start != 0 {
378+ let body_size = end - start;
379+ println ! (
380+ "{:?} 206 {} {} {} {} {}" ,
381+ remote_addr, body_size, human_time, method, filepath, user_agent_str
382+ ) ;
375383 return ( StatusCode :: PARTIAL_CONTENT , headers, axbody) . into_response ( ) ;
376384 }
385+ println ! (
386+ "{:?} 200 {} {} {} {} {}" ,
387+ remote_addr,
388+ metadata. len( ) ,
389+ human_time,
390+ method,
391+ filepath,
392+ user_agent_str
393+ ) ;
377394 return ( StatusCode :: OK , headers, axbody) . into_response ( ) ;
378395 }
379396 Err ( _) => {
380397 println ! ( "Error opening file in ax_get_file" ) ;
398+ println ! (
399+ "{:?} 404 0 {} {} {} {}" ,
400+ remote_addr, human_time, method, filepath, user_agent_str
401+ ) ;
381402 return ( StatusCode :: NOT_FOUND , headers, Body :: empty ( ) ) . into_response ( ) ;
382403 }
383404 } ;
0 commit comments