1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-27 10:39:03 +02:00

allow user to set the cookie HttpOnly policy for the redis session (#36)

* allow user to set the cookie HttpOnly policy for the redis session

Signed-off-by: Bart Willems <bwillems@protonmail.com>
This commit is contained in:
Bart Willems
2020-03-29 14:36:01 +02:00
committed by GitHub
parent f878889627
commit f4bcebdecd
4 changed files with 112 additions and 1 deletions

View File

@ -42,6 +42,7 @@ impl RedisSession {
secure: false,
max_age: Some(Duration::days(7)),
same_site: None,
http_only: Some(true),
}))
}
@ -89,6 +90,12 @@ impl RedisSession {
self
}
/// Set custom cookie HttpOnly policy
pub fn cookie_http_only(mut self, http_only: bool) -> Self {
Rc::get_mut(&mut self.0).unwrap().http_only = Some(http_only);
self
}
/// Set a custom cache key generation strategy, expecting session key as input
pub fn cache_keygen(mut self, keygen: Box<dyn Fn(&str) -> String>) -> Self {
Rc::get_mut(&mut self.0).unwrap().cache_keygen = keygen;
@ -205,6 +212,7 @@ struct Inner {
secure: bool,
max_age: Option<Duration>,
same_site: Option<SameSite>,
http_only: Option<bool>,
}
impl Inner {
@ -278,7 +286,7 @@ impl Inner {
let mut cookie = Cookie::new(self.name.clone(), value.clone());
cookie.set_path(self.path.clone());
cookie.set_secure(self.secure);
cookie.set_http_only(true);
cookie.set_http_only(self.http_only.unwrap_or(true));
if let Some(ref domain) = self.domain {
cookie.set_domain(domain.clone());