1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-27 15:29:03 +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

@ -53,7 +53,7 @@ use std::rc::Rc;
use actix_service::{Service, Transform};
use futures::future::{ok, Either, FutureResult};
use futures::{Future, IntoFuture, Poll};
use chrono::Duration;
use time::Duration;
use crate::cookie::{Cookie, CookieJar, Key, SameSite};
use crate::error::{Error, Result};
@ -427,16 +427,16 @@ impl CookieIdentityPolicy {
self
}
/// Sets the `max-age` field in the session cookie being built with given number of seconds.
pub fn max_age(self, seconds: i64) -> CookieIdentityPolicy {
self.max_age_time(Duration::seconds(seconds))
}
/// Sets the `max-age` field in the session cookie being built with `chrono::Duration`.
pub fn max_age_time(mut self, value: Duration) -> CookieIdentityPolicy {
Rc::get_mut(&mut self.0).unwrap().max_age = Some(value);
self
}
/// Sets the `max-age` field in the session cookie being built with given number of seconds.
pub fn max_age(mut self, seconds: isize) -> CookieIdentityPolicy {
Rc::get_mut(&mut self.0).unwrap().max_age = Some(Duration::seconds(seconds as i64));
self
}
/// Sets the `same_site` field in the session cookie being built.
pub fn same_site(mut self, same_site: SameSite) -> Self {
@ -547,7 +547,7 @@ mod tests {
.service(web::resource("/login").to(|id: Identity| {
id.remember("test".to_string());
HttpResponse::Ok()
}))
})),
);
let resp =
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request());
@ -559,7 +559,7 @@ mod tests {
#[test]
fn test_identity_max_age() {
let seconds = 60isize;
let seconds = 60;
let mut srv = test::init_service(
App::new()
.wrap(IdentityService::new(
@ -573,7 +573,7 @@ mod tests {
.service(web::resource("/login").to(|id: Identity| {
id.remember("test".to_string());
HttpResponse::Ok()
}))
})),
);
let resp =
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request());

View File

@ -1,8 +1,8 @@
//! `Middleware` to normalize request's URI
use regex::Regex;
use actix_service::{Service, Transform};
use futures::future::{self, FutureResult};
use regex::Regex;
use crate::service::{ServiceRequest, ServiceResponse};
@ -28,7 +28,7 @@ where
fn new_transform(&self, service: S) -> Self::Future {
future::ok(NormalizePathNormalization {
service,
merge_slash: Regex::new("//+").unwrap()
merge_slash: Regex::new("//+").unwrap(),
})
}
}
@ -72,7 +72,6 @@ mod tests {
use super::*;
use crate::dev::ServiceRequest;
use crate::http::header::CONTENT_TYPE;
use crate::test::{block_on, TestRequest};
use crate::HttpResponse;