@@ -19,13 +19,12 @@ use axum::{
1919use colored:: Colorize ;
2020use sentry_tower:: SentryHttpLayer ;
2121use serde_json:: json;
22- use sha1 :: Digest ;
22+ use sha2 :: Digest ;
2323use std:: { net:: IpAddr , sync:: Arc , time:: Instant } ;
2424use tokio:: sync:: RwLock ;
2525use tower:: Layer ;
2626use tower_http:: {
2727 catch_panic:: CatchPanicLayer , cors:: CorsLayer , normalize_path:: NormalizePathLayer ,
28- trace:: TraceLayer ,
2928} ;
3029use utoipa:: openapi:: security:: { ApiKey , ApiKeyValue , SecurityScheme } ;
3130use utoipa_axum:: router:: OpenApiRouter ;
@@ -50,7 +49,7 @@ fn handle_panic(_err: Box<dyn std::any::Any + Send + 'static>) -> Response<Body>
5049 . unwrap ( )
5150}
5251
53- fn handle_request ( req : & Request < Body > , _span : & tracing :: Span ) {
52+ async fn handle_request ( req : Request < Body > , next : Next ) -> Result < Response , StatusCode > {
5453 let ip = extract_ip ( req. headers ( ) )
5554 . map ( |ip| ip. to_string ( ) )
5655 . unwrap_or_else ( || "unknown" . to_string ( ) ) ;
@@ -70,13 +69,15 @@ fn handle_request(req: &Request<Body>, _span: &tracing::Span) {
7069 format!( "({})" , ip) . bright_black( ) ,
7170 ) ,
7271 ) ;
72+
73+ Ok ( next. run ( req) . await )
7374}
7475
7576async fn handle_etag ( req : Request , next : Next ) -> Result < Response , StatusCode > {
7677 let if_none_match = req. headers ( ) . get ( "If-None-Match" ) . cloned ( ) ;
7778
7879 let response = next. run ( req) . await ;
79- let mut hash = sha1 :: Sha1 :: new ( ) ;
80+ let mut hash = sha2 :: Sha256 :: new ( ) ;
8081
8182 let ( mut parts, body) = response. into_parts ( ) ;
8283 let body_bytes = axum:: body:: to_bytes ( body, usize:: MAX ) . await . unwrap ( ) ;
@@ -202,7 +203,7 @@ async fn main() {
202203 } )
203204 . layer ( CatchPanicLayer :: custom ( handle_panic) )
204205 . layer ( CorsLayer :: very_permissive ( ) )
205- . layer ( TraceLayer :: new_for_http ( ) . on_request ( handle_request) )
206+ . layer ( axum :: middleware :: from_fn ( handle_request) )
206207 . route_layer ( axum:: middleware:: from_fn ( handle_etag) )
207208 . route_layer ( SentryHttpLayer :: with_transaction ( ) )
208209 . with_state ( state. clone ( ) ) ;
0 commit comments