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:
commit
7c71171602
1 changed files with 13 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue