@@ -35,31 +35,31 @@ impl<T> Clone for WebhookState<T> {
3535/// use topgg::{Vote, Webhook}; 
3636/// use tokio::net::TcpListener; 
3737/// use std::sync::Arc; 
38- ///   
38+ /// 
3939/// struct MyVoteListener {} 
40- ///   
40+ /// 
4141/// #[async_trait::async_trait] 
4242/// impl Webhook<Vote> for MyVoteListener { 
4343///   async fn callback(&self, vote: Vote) { 
4444///     println!("A user with the ID of {} has voted us on Top.gg!", vote.voter_id); 
4545///   } 
4646/// } 
47- ///   
47+ /// 
4848/// async fn index() -> &'static str { 
4949///   "Hello, World!" 
5050/// } 
51- ///   
51+ /// 
5252/// #[tokio::main] 
5353/// async fn main() { 
5454///   let state = Arc::new(MyVoteListener {}); 
55- ///   
55+ /// 
5656///   let router = Router::new().route("/", get(index)).nest( 
5757///     "/votes", 
5858///     topgg::axum::webhook(env!("MY_TOPGG_WEBHOOK_SECRET").to_string(), Arc::clone(&state)), 
5959///   ); 
60- ///   
60+ /// 
6161///   let listener = TcpListener::bind("127.0.0.1:8080").await.unwrap(); 
62- ///   
62+ /// 
6363///   axum::serve(listener, router).await.unwrap(); 
6464/// } 
6565/// ``` 
@@ -71,21 +71,26 @@ where
7171  T :  Webhook < D > , 
7272{ 
7373  Router :: new ( ) 
74-     . route ( "/" ,  post ( async  |headers :  HeaderMap ,  State ( webhook) :  State < WebhookState < T > > ,  body :  String | { 
75-       if  let  Some ( authorization)  = headers. get ( "Authorization" )  { 
76-         if  let  Ok ( authorization)  = authorization. to_str ( )  { 
77-           if  authorization == * ( webhook. password )  { 
78-             if  let  Ok ( data)  = serde_json:: from_str ( & body)  { 
79-               webhook. state . callback ( data) . await ; 
80-     
81-               return  ( StatusCode :: NO_CONTENT ,  ( ) ) . into_response ( ) ; 
74+     . route ( 
75+       "/" , 
76+       post ( 
77+         async  |headers :  HeaderMap ,  State ( webhook) :  State < WebhookState < T > > ,  body :  String | { 
78+           if  let  Some ( authorization)  = headers. get ( "Authorization" )  { 
79+             if  let  Ok ( authorization)  = authorization. to_str ( )  { 
80+               if  authorization == * ( webhook. password )  { 
81+                 if  let  Ok ( data)  = serde_json:: from_str ( & body)  { 
82+                   webhook. state . callback ( data) . await ; 
83+ 
84+                   return  ( StatusCode :: NO_CONTENT ,  ( ) ) . into_response ( ) ; 
85+                 } 
86+               } 
8287            } 
8388          } 
84-          } 
85-       } 
86-     
87-       ( StatusCode :: UNAUTHORIZED ,   ( ) ) . into_response ( ) 
88-     } ) ) 
89+ 
90+            ( StatusCode :: UNAUTHORIZED ,   ( ) ) . into_response ( ) 
91+          } , 
92+       ) , 
93+     ) 
8994    . with_state ( WebhookState  { 
9095      state, 
9196      password :  Arc :: new ( password) , 
0 commit comments