1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-10 02:49:33 +00:00

Merge pull request #248 from bbigras/same-site

Add same-site to CookieSessionBackend
This commit is contained in:
Nikolay Kim 2018-05-26 08:02:12 -07:00 committed by GitHub
commit 7c71171602
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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);