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

@ -1,5 +1,14 @@
# Changes
## [0.1.1] - 2019-04-19
### Changes
* Cookie::max_age() accepts value in seconds
* Cookie::max_age_time() accepts value in time::Duration
## [0.1.0] - 2019-04-16
### Added

View File

@ -77,7 +77,7 @@ serde_json = "1.0"
sha1 = "0.6"
slab = "0.4"
serde_urlencoded = "0.5.5"
time = "0.1"
time = "0.1.42"
tokio-tcp = "0.1.3"
tokio-timer = "0.2.8"
tokio-current-thread = "0.1"

View File

@ -1,7 +1,7 @@
use std::borrow::Cow;
use time::Tm;
use chrono::Duration;
use time::Tm;
use super::{Cookie, SameSite};
@ -17,7 +17,6 @@ use super::{Cookie, SameSite};
///
/// ```rust
/// use actix_http::cookie::Cookie;
/// use chrono::Duration;
///
/// # fn main() {
/// let cookie: Cookie = Cookie::build("name", "value")
@ -25,7 +24,7 @@ use super::{Cookie, SameSite};
/// .path("/")
/// .secure(true)
/// .http_only(true)
/// .max_age(Duration::days(1))
/// .max_age(84600)
/// .finish();
/// # }
/// ```
@ -80,6 +79,26 @@ impl CookieBuilder {
self
}
/// Sets the `max_age` field in seconds in the cookie being built.
///
/// # Example
///
/// ```rust
/// use actix_http::cookie::Cookie;
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .max_age(1800)
/// .finish();
///
/// assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));
/// # }
/// ```
#[inline]
pub fn max_age(self, seconds: i64) -> CookieBuilder {
self.max_age_time(Duration::seconds(seconds))
}
/// Sets the `max_age` field in the cookie being built.
///
/// # Example
@ -89,14 +108,14 @@ impl CookieBuilder {
///
/// # fn main() {
/// let c = Cookie::build("foo", "bar")
/// .max_age(time::Duration::minutes(30))
/// .max_age_time(time::Duration::minutes(30))
/// .finish();
///
/// assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));
/// # }
/// ```
#[inline]
pub fn max_age(mut self, value: Duration) -> CookieBuilder {
pub fn max_age_time(mut self, value: Duration) -> CookieBuilder {
self.cookie.set_max_age(value);
self
}

View File

@ -537,8 +537,8 @@ mod test {
#[test]
#[cfg(feature = "secure-cookies")]
fn delta() {
use std::collections::HashMap;
use chrono::Duration;
use std::collections::HashMap;
let mut c = CookieJar::new();

View File

@ -65,9 +65,9 @@ use std::borrow::Cow;
use std::fmt;
use std::str::FromStr;
use chrono::Duration;
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
use time::Tm;
use chrono::Duration;
pub use self::builder::CookieBuilder;
pub use self::draft::*;
@ -979,7 +979,6 @@ impl<'a, 'b> PartialEq<Cookie<'b>> for Cookie<'a> {
mod tests {
use super::{Cookie, SameSite};
use time::strptime;
use chrono::Duration;
#[test]
fn format() {
@ -989,9 +988,7 @@ mod tests {
let cookie = Cookie::build("foo", "bar").http_only(true).finish();
assert_eq!(&cookie.to_string(), "foo=bar; HttpOnly");
let cookie = Cookie::build("foo", "bar")
.max_age(Duration::seconds(10))
.finish();
let cookie = Cookie::build("foo", "bar").max_age(10).finish();
assert_eq!(&cookie.to_string(), "foo=bar; Max-Age=10");
let cookie = Cookie::build("foo", "bar").secure(true).finish();

View File

@ -5,8 +5,8 @@ use std::error::Error;
use std::fmt;
use std::str::Utf8Error;
use percent_encoding::percent_decode;
use chrono::Duration;
use percent_encoding::percent_decode;
use super::{Cookie, CookieStr, SameSite};
@ -220,8 +220,8 @@ where
#[cfg(test)]
mod tests {
use super::{Cookie, SameSite};
use time::strptime;
use chrono::Duration;
use time::strptime;
macro_rules! assert_eq_parse {
($string:expr, $expected:expr) => {
@ -419,9 +419,7 @@ mod tests {
#[test]
fn do_not_panic_on_large_max_ages() {
let max_seconds = Duration::max_value().num_seconds();
let expected = Cookie::build("foo", "bar")
.max_age(Duration::seconds(max_seconds))
.finish();
let expected = Cookie::build("foo", "bar").max_age(max_seconds).finish();
assert_eq_parse!(format!(" foo=bar; Max-Age={:?}", max_seconds + 1), expected);
}
}

View File

@ -860,7 +860,7 @@ mod tests {
.domain("www.rust-lang.org")
.path("/test")
.http_only(true)
.max_age(time::Duration::days(1))
.max_age_time(time::Duration::days(1))
.finish(),
)
.del_cookie(&cookies[1])