From 687f3778f2fed2fe4aba8027c215ce91c54648ed Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 31 Mar 2023 23:55:20 +0000 Subject: feat(router): expose response to post-route callback --- Cargo.toml | 2 +- README.md | 8 ++++---- examples/windmark.rs | 3 ++- src/handler.rs | 2 +- src/router.rs | 7 ++++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d32896..4cf6dc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "windmark" -version = "0.2.4" +version = "0.2.5" authors = ["Fuwn "] edition = "2021" description = "An elegant and highly performant async Gemini server framework" diff --git a/README.md b/README.md index 24c2a45..990c0a6 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,18 @@ Check out an example starter project # Cargo.toml [dependencies] -windmark = "0.2.4" +windmark = "0.2.5" tokio = { version = "0.2.4", features = ["full"] } # If you would like to use the built-in logger (recommended) -# windmark = { version = "0.2.4", features = ["logger"] } +# windmark = { version = "0.2.5", features = ["logger"] } # If you would like to use the built-in MIME dedection when `Success`-ing a file # (recommended) -# windmark = { version = "0.2.4", features = ["auto-deduce-mime"] } +# windmark = { version = "0.2.5", features = ["auto-deduce-mime"] } # If you would like to use macro-based responses (as seen below) -# windmark = { version = "0.2.4", features = ["response-macros"] } +# windmark = { version = "0.2.5", features = ["response-macros"] } ``` ### Implement a Windmark server diff --git a/examples/windmark.rs b/examples/windmark.rs index 4507048..e5dcd52 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -85,7 +85,8 @@ async fn main() -> Result<(), Box> { ) })); router.set_post_route_callback(Box::new(|context, content| { - *content = content.replace("Welcome!", "Welcome to Windmark!"); + content.content = + content.content.replace("Welcome!", "Welcome to Windmark!"); info!( "closed connection from {}", diff --git a/src/handler.rs b/src/handler.rs index bd64f03..3429f3b 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -28,5 +28,5 @@ pub type ErrorResponse = Box) -> Response + Send + Sync>; pub type Callback = Box) + Send + Sync>; pub type CleanupCallback = - Box, &mut String) + Send + Sync>; + Box, &mut Response) + Send + Sync>; pub type Partial = Box) -> String + Send + Sync>; diff --git a/src/router.rs b/src/router.rs index a89f230..b2c0435 100644 --- a/src/router.rs +++ b/src/router.rs @@ -326,6 +326,7 @@ impl Router { &stream.ssl().peer_certificate(), )); + let peer_certificate = stream.ssl().peer_certificate(); let mut content = if let Ok(ref route) = route { let footers_length = (*self.footers.lock().unwrap()).len(); @@ -364,13 +365,13 @@ impl Router { stream.get_ref(), &url, &route.params, - &stream.ssl().peer_certificate(), + &peer_certificate, )) } else { (*self.error_handler).lock().unwrap()(ErrorContext::new( stream.get_ref(), &url, - &stream.ssl().peer_certificate(), + &peer_certificate, )) }; @@ -390,7 +391,7 @@ impl Router { route.as_ref().map_or(None, |route| Some(&route.params)), &stream.ssl().peer_certificate(), ), - &mut content.content, + &mut content, ); stream -- cgit v1.2.3