🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(context): bring back peer address

Fuwn 50601e32 71bbd199

+47 -29
+16 -16
examples/windmark.rs
··· 80 80 r.mount("/module", success!("This is a module!")); 81 81 }); 82 82 router.attach_async(Clicker::default()); 83 - // router.set_pre_route_callback(|context| { 84 - // info!( 85 - // "accepted connection from {} to {}", 86 - // context.tcp.peer_addr().unwrap().ip(), 87 - // context.url.to_string() 88 - // ) 89 - // }); 90 - // router.set_post_route_callback(|context, content| { 91 - // content.content = 92 - // content.content.replace("Welcome!", "Welcome to Windmark!"); 93 - // 94 - // info!( 95 - // "closed connection from {}", 96 - // context.tcp.peer_addr().unwrap().ip() 97 - // ) 98 - // }); 83 + router.set_pre_route_callback(|context| { 84 + info!( 85 + "accepted connection from {} to {}", 86 + context.peer_address.unwrap().ip(), 87 + context.url.to_string() 88 + ) 89 + }); 90 + router.set_post_route_callback(|context, content| { 91 + content.content = 92 + content.content.replace("Welcome!", "Welcome to Windmark!"); 93 + 94 + info!( 95 + "closed connection from {}", 96 + context.peer_address.unwrap().ip() 97 + ) 98 + }); 99 99 router.add_header(|_| "```\nART IS COOL\n```\nhi".to_string()); 100 100 router.add_footer(|_| "Copyright 2022".to_string()); 101 101 router.add_footer(|context| {
+9 -3
src/context/error.rs
··· 22 22 #[allow(clippy::module_name_repetitions)] 23 23 #[derive(Clone)] 24 24 pub struct ErrorContext { 25 - pub url: Url, 26 - pub certificate: Option<X509>, 25 + pub peer_address: Option<std::net::SocketAddr>, 26 + pub url: Url, 27 + pub certificate: Option<X509>, 27 28 } 28 29 29 30 impl ErrorContext { 30 31 #[must_use] 31 - pub const fn new(url: Url, certificate: Option<X509>) -> Self { 32 + pub fn new( 33 + peer_address: std::io::Result<std::net::SocketAddr>, 34 + url: Url, 35 + certificate: Option<X509>, 36 + ) -> Self { 32 37 Self { 38 + peer_address: peer_address.ok(), 33 39 url, 34 40 certificate, 35 41 }
+7 -4
src/context/hook.rs
··· 23 23 #[allow(clippy::module_name_repetitions)] 24 24 #[derive(Clone)] 25 25 pub struct HookContext<'a> { 26 - pub url: Url, 27 - pub params: Option<Params<'a, 'a>>, 28 - pub certificate: Option<X509>, 26 + pub peer_address: Option<std::net::SocketAddr>, 27 + pub url: Url, 28 + pub params: Option<Params<'a, 'a>>, 29 + pub certificate: Option<X509>, 29 30 } 30 31 31 32 impl<'a> HookContext<'a> { 32 33 #[must_use] 33 - pub const fn new( 34 + pub fn new( 35 + peer_address: std::io::Result<std::net::SocketAddr>, 34 36 url: Url, 35 37 params: Option<Params<'a, 'a>>, 36 38 certificate: Option<X509>, 37 39 ) -> Self { 38 40 Self { 41 + peer_address: peer_address.ok(), 39 42 url, 40 43 params, 41 44 certificate,
+7 -4
src/context/route.rs
··· 23 23 #[allow(clippy::module_name_repetitions)] 24 24 #[derive(Clone)] 25 25 pub struct RouteContext<'a> { 26 - pub url: Url, 27 - pub params: Params<'a, 'a>, 28 - pub certificate: Option<X509>, 26 + pub peer_address: Option<std::net::SocketAddr>, 27 + pub url: Url, 28 + pub params: Params<'a, 'a>, 29 + pub certificate: Option<X509>, 29 30 } 30 31 31 32 impl<'a> RouteContext<'a> { 32 33 #[must_use] 33 - pub const fn new( 34 + pub fn new( 35 + peer_address: std::io::Result<std::net::SocketAddr>, 34 36 url: Url, 35 37 params: Params<'a, 'a>, 36 38 certificate: Option<X509>, 37 39 ) -> Self { 38 40 Self { 41 + peer_address: peer_address.ok(), 39 42 url, 40 43 params, 41 44 certificate,
+8 -2
src/router.rs
··· 346 346 let route = &mut self.routes.at(&fixed_path); 347 347 let peer_certificate = stream.ssl().peer_certificate(); 348 348 let hook_context = HookContext::new( 349 + stream.get_ref().peer_addr(), 349 350 url.clone(), 350 351 route 351 352 .as_ref() ··· 365 366 366 367 let mut content = if let Ok(ref route) = route { 367 368 let footers_length = (*self.footers.lock().unwrap()).len(); 368 - let route_context = 369 - RouteContext::new(url.clone(), route.params.clone(), peer_certificate); 369 + let route_context = RouteContext::new( 370 + stream.get_ref().peer_addr(), 371 + url.clone(), 372 + route.params.clone(), 373 + peer_certificate, 374 + ); 370 375 371 376 for partial_header in &mut *self.headers.lock().unwrap() { 372 377 header ··· 394 399 handler.await 395 400 } else { 396 401 (*self.error_handler).lock().unwrap()(ErrorContext::new( 402 + stream.get_ref().peer_addr(), 397 403 url.clone(), 398 404 peer_certificate, 399 405 ))