1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01:00

Add same-site to CookieSessionBackend

closes #247
This commit is contained in:
Bruno Bigras 2018-05-25 19:15:00 -04:00
parent 255cd4917d
commit 4dcecd907b

View File

@ -69,7 +69,7 @@ use std::marker::PhantomData;
use std::rc::Rc;
use std::sync::Arc;
use cookie::{Cookie, CookieJar, Key};
use cookie::{Cookie, CookieJar, Key, SameSite};
use futures::future::{err as FutErr, ok as FutOk, FutureResult};
use futures::Future;
use http::header::{self, HeaderValue};
@ -367,6 +367,7 @@ struct CookieSessionInner {
domain: Option<String>,
secure: bool,
max_age: Option<Duration>,
same_site: Option<SameSite>,
}
impl CookieSessionInner {
@ -379,6 +380,7 @@ impl CookieSessionInner {
domain: None,
secure: true,
max_age: None,
same_site: None,
}
}
@ -404,6 +406,10 @@ impl CookieSessionInner {
cookie.set_max_age(max_age);
}
if let Some(same_site) = self.same_site {
cookie.set_same_site(same_site);
}
let mut jar = CookieJar::new();
match self.security {
@ -531,6 +537,12 @@ impl CookieSessionBackend {
self
}
/// Sets the `same_site` field in the session cookie being built.
pub fn same_site(mut self, value: SameSite) -> CookieSessionBackend {
Rc::get_mut(&mut self.0).unwrap().same_site = Some(value);
self
}
/// Sets the `max-age` field in the session cookie being built.
pub fn max_age(mut self, value: Duration) -> CookieSessionBackend {
Rc::get_mut(&mut self.0).unwrap().max_age = Some(value);