mirror of
https://github.com/actix/actix-web.git
synced 2024-05-19 16:58:14 +00:00
Merge 0b2069472f
into ba7fd048b6
This commit is contained in:
commit
b07c95867e
|
@ -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
|
||||
|
||||
|
|
|
@ -110,6 +110,12 @@ impl<'a> GuardContext<'a> {
|
|||
pub fn header<H: Header>(&self) -> Option<H> {
|
||||
H::parse(self.req).ok()
|
||||
}
|
||||
|
||||
/// Counterpart to [HttpRequest::app_data](crate::HttpRequest::app_data).
|
||||
#[inline]
|
||||
pub fn app_data<T: 'static>(&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::<u32>()) == 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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue