aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/windmark.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs
index 0c5b13b..eaf7b43 100644
--- a/examples/windmark.rs
+++ b/examples/windmark.rs
@@ -199,9 +199,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
})
});
- // router.mount("", Box::new(|_| {
- // Response::Success("hi".into())
- // }));
+ router.mount(
+ "/secret",
+ Box::new(|context| {
+ if let Some(certificate) = context.certificate {
+ Response::Success(format!("Your public key: {}.", {
+ (|| -> Result<String, openssl::error::ErrorStack> {
+ Ok(format!(
+ "{:?}",
+ certificate.public_key()?.rsa()?.public_key_to_pem()?
+ ))
+ })()
+ .unwrap_or_else(|_| "Unknown".to_string())
+ },))
+ } else {
+ Response::ClientCertificateRequired(
+ "This is a secret route! Identify yourself!".to_string(),
+ )
+ }
+ }),
+ );
router.run().await
}