mirror of
https://github.com/actix/actix-web.git
synced 2024-06-02 13:29:24 +00:00
changes: guard
This commit is contained in:
parent
ba7fd048b6
commit
09ff35a602
|
@ -5,6 +5,7 @@
|
||||||
### Added
|
### 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.
|
- 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
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,12 @@ impl<'a> GuardContext<'a> {
|
||||||
pub fn header<H: Header>(&self) -> Option<H> {
|
pub fn header<H: Header>(&self) -> Option<H> {
|
||||||
H::parse(self.req).ok()
|
H::parse(self.req).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Counterpart to [`HttpRequest::app_data`].
|
||||||
|
#[inline]
|
||||||
|
pub fn app_data<T: 'static>(&self) -> Option<&T> {
|
||||||
|
self.req.app_data()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interface for routing guards.
|
/// Interface for routing guards.
|
||||||
|
@ -512,4 +518,18 @@ mod tests {
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
assert!(guard.check(&req.guard_ctx()));
|
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