1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

drop chrono and use i64 for max age

This commit is contained in:
Nikolay Kim
2019-04-19 17:23:17 -07:00
parent a3844c1bfd
commit 7292d0b696
15 changed files with 70 additions and 41 deletions

View File

@ -17,7 +17,6 @@
use std::collections::HashMap;
use std::rc::Rc;
use std::time::Duration;
use actix_service::{Service, Transform};
use actix_web::cookie::{Cookie, CookieJar, Key, SameSite};
@ -57,7 +56,7 @@ struct CookieSessionInner {
domain: Option<String>,
secure: bool,
http_only: bool,
max_age: Option<Duration>,
max_age: Option<time::Duration>,
same_site: Option<SameSite>,
}
@ -98,7 +97,7 @@ impl CookieSessionInner {
}
if let Some(max_age) = self.max_age {
cookie.set_max_age(time::Duration::from_std(max_age).unwrap());
cookie.set_max_age(max_age);
}
if let Some(same_site) = self.same_site {
@ -250,7 +249,12 @@ impl CookieSession {
}
/// Sets the `max-age` field in the session cookie being built.
pub fn max_age(mut self, value: Duration) -> CookieSession {
pub fn max_age(self, seconds: i64) -> CookieSession {
self.max_age_time(time::Duration::seconds(seconds))
}
/// Sets the `max-age` field in the session cookie being built.
pub fn max_age_time(mut self, value: time::Duration) -> CookieSession {
Rc::get_mut(&mut self.0).unwrap().max_age = Some(value);
self
}
@ -390,7 +394,7 @@ mod tests {
.domain("localhost")
.http_only(true)
.same_site(SameSite::Lax)
.max_age(Duration::from_secs(100)),
.max_age(100),
)
.service(web::resource("/").to(|ses: Session| {
let _ = ses.set("counter", 100);