mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
added Httprequest::cookie() method
This commit is contained in:
parent
f0531793b4
commit
edac148f7c
@ -82,10 +82,20 @@ impl HttpRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return request cookies.
|
/// Return request cookies.
|
||||||
pub fn cookies(&mut self) -> &Vec<Cookie<'static>> {
|
pub fn cookies(&self) -> &Vec<Cookie<'static>> {
|
||||||
&self.cookies
|
&self.cookies
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return request cookie.
|
||||||
|
pub fn cookie(&self, name: &str) -> Option<&Cookie> {
|
||||||
|
for cookie in &self.cookies {
|
||||||
|
if cookie.name() == name {
|
||||||
|
return Some(&cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Load cookies
|
/// Load cookies
|
||||||
pub fn load_cookies(&mut self) -> Result<&Vec<Cookie>, CookieParseError>
|
pub fn load_cookies(&mut self) -> Result<&Vec<Cookie>, CookieParseError>
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,12 @@ fn test_request_cookies() {
|
|||||||
assert_eq!(cookies[0].value(), "value1");
|
assert_eq!(cookies[0].value(), "value1");
|
||||||
assert_eq!(cookies[1].name(), "cookie2");
|
assert_eq!(cookies[1].name(), "cookie2");
|
||||||
assert_eq!(cookies[1].value(), "value2");
|
assert_eq!(cookies[1].value(), "value2");
|
||||||
|
|
||||||
|
let cookie = req.cookie("cookie1");
|
||||||
|
assert!(cookie.is_some());
|
||||||
|
let cookie = cookie.unwrap();
|
||||||
|
assert_eq!(cookie.name(), "cookie1");
|
||||||
|
assert_eq!(cookie.value(), "value1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user