From 09ff35a60264d7d6eba3cace282a44ea3e008d24 Mon Sep 17 00:00:00 2001 From: Raphael C Date: Wed, 24 Apr 2024 20:56:43 +0200 Subject: [PATCH 1/3] changes: guard --- actix-web/CHANGES.md | 1 + actix-web/src/guard/mod.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index c6454ed65fc..f370f38a476 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -5,6 +5,7 @@ ### Added - Add `unicode` crate feature (on-by-default) to switch between `regex` and `regex-lite` as a trade-off between full unicode support and binary size. +- Support for app_data method in a GuardContext ### Changed diff --git a/actix-web/src/guard/mod.rs b/actix-web/src/guard/mod.rs index 9451a60f903..f2b13c59caf 100644 --- a/actix-web/src/guard/mod.rs +++ b/actix-web/src/guard/mod.rs @@ -110,6 +110,12 @@ impl<'a> GuardContext<'a> { pub fn header(&self) -> Option { H::parse(self.req).ok() } + + /// Counterpart to [`HttpRequest::app_data`]. + #[inline] + pub fn app_data(&self) -> Option<&T> { + self.req.app_data() + } } /// Interface for routing guards. @@ -512,4 +518,18 @@ mod tests { .to_srv_request(); assert!(guard.check(&req.guard_ctx())); } + + #[test] + fn app_data() { + const TEST_VALUE: u32 = 42; + let guard = fn_guard(|ctx| dbg!(ctx.app_data::()) == Some(&TEST_VALUE)); + + let req = TestRequest::default().app_data(TEST_VALUE).to_srv_request(); + assert!(guard.check(&req.guard_ctx())); + + let req = TestRequest::default() + .app_data(TEST_VALUE * 2) + .to_srv_request(); + assert!(!guard.check(&req.guard_ctx())); + } } From 0b2069472f0d62dfdd2d9a1eec8911f52533c01e Mon Sep 17 00:00:00 2001 From: GreeFine Date: Thu, 25 Apr 2024 10:39:37 +0200 Subject: [PATCH 2/3] fix(guard): docs link to app_data --- actix-web/src/guard/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actix-web/src/guard/mod.rs b/actix-web/src/guard/mod.rs index f2b13c59caf..41609953ad0 100644 --- a/actix-web/src/guard/mod.rs +++ b/actix-web/src/guard/mod.rs @@ -111,7 +111,7 @@ impl<'a> GuardContext<'a> { H::parse(self.req).ok() } - /// Counterpart to [`HttpRequest::app_data`]. + /// Counterpart to [HttpRequest::app_data](crate::HttpRequest::app_data). #[inline] pub fn app_data(&self) -> Option<&T> { self.req.app_data() From 4a9e14279ce3d7e3c7d098731073841ae7432140 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 7 Jun 2024 15:05:31 +0100 Subject: [PATCH 3/3] docs: fix changelog --- actix-web/CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 147a71f94da..6734a626af5 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -2,6 +2,10 @@ ## Unreleased +# Added + +- Add `guard::GuardContext::app_data()` method. + ## 4.6.0 ### Added @@ -10,7 +14,6 @@ - Add `rustls-0_23` crate feature. - Add `HttpServer::{bind_rustls_0_23, listen_rustls_0_23}()` builder methods. - Add `HttpServer::tls_handshake_timeout()` builder method for `rustls-0_22` and `rustls-0_23`. -- Add `app_data` method for `actix_web::guard::GuardContext` ### Changed