diff --git a/actix-http/src/cookie/mod.rs b/actix-http/src/cookie/mod.rs index 66ed1d487..224ead1d4 100644 --- a/actix-http/src/cookie/mod.rs +++ b/actix-http/src/cookie/mod.rs @@ -992,7 +992,7 @@ impl<'a, 'b> PartialEq> for Cookie<'a> { #[cfg(test)] mod tests { use super::{Cookie, SameSite}; - use time::OffsetDateTime; + use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset}; #[test] fn format() { @@ -1017,7 +1017,7 @@ mod tests { assert_eq!(&cookie.to_string(), "foo=bar; Domain=www.rust-lang.org"); let time_str = "Wed, 21 Oct 2015 07:28:00 GMT"; - let expires = OffsetDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap(); + let expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap().using_offset(UtcOffset::UTC); let cookie = Cookie::build("foo", "bar").expires(expires).finish(); assert_eq!( &cookie.to_string(), diff --git a/actix-http/src/cookie/parse.rs b/actix-http/src/cookie/parse.rs index 2d026749d..60dd5ad30 100644 --- a/actix-http/src/cookie/parse.rs +++ b/actix-http/src/cookie/parse.rs @@ -6,7 +6,7 @@ use std::fmt; use std::str::Utf8Error; use percent_encoding::percent_decode; -use time::{Duration, OffsetDateTime}; +use time::{Duration, PrimitiveDateTime, UtcOffset}; use super::{Cookie, CookieStr, SameSite}; @@ -182,13 +182,13 @@ fn parse_inner<'c>(s: &str, decode: bool) -> Result, ParseError> { // Try parsing with three date formats according to // http://tools.ietf.org/html/rfc2616#section-3.3.1. Try // additional ones as encountered in the real world. - let tm = OffsetDateTime::parse(v, "%a, %d %b %Y %H:%M:%S") - .or_else(|_| OffsetDateTime::parse(v, "%A, %d-%b-%y %H:%M:%S")) - .or_else(|_| OffsetDateTime::parse(v, "%a, %d-%b-%Y %H:%M:%S")) - .or_else(|_| OffsetDateTime::parse(v, "%a %b %d %H:%M:%S %Y")); + let tm = PrimitiveDateTime::parse(v, "%a, %d %b %Y %H:%M:%S") + .or_else(|_| PrimitiveDateTime::parse(v, "%A, %d-%b-%y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(v, "%a, %d-%b-%Y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(v, "%a %b %d %H:%M:%S %Y")); if let Ok(time) = tm { - cookie.expires = Some(time) + cookie.expires = Some(time.using_offset(UtcOffset::UTC)) } } _ => { @@ -216,7 +216,7 @@ where #[cfg(test)] mod tests { use super::{Cookie, SameSite}; - use time::{Duration, OffsetDateTime}; + use time::{Duration, OffsetDateTime, PrimitiveDateTime, UtcOffset}; macro_rules! assert_eq_parse { ($string:expr, $expected:expr) => { @@ -376,7 +376,7 @@ mod tests { ); let time_str = "Wed, 21 Oct 2015 07:28:00 GMT"; - let expires = OffsetDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap(); + let expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap().using_offset(UtcOffset::UTC); expected.set_expires(expires); assert_eq_parse!( " foo=bar ;HttpOnly; Secure; Max-Age=4; Path=/foo; \ @@ -385,7 +385,7 @@ mod tests { ); unexpected.set_domain("foo.com"); - let bad_expires = OffsetDateTime::parse(time_str, "%a, %d %b %Y %H:%S:%M").unwrap(); + let bad_expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%S:%M").unwrap().using_offset(UtcOffset::UTC); expected.set_expires(bad_expires); assert_ne_parse!( " foo=bar ;HttpOnly; Secure; Max-Age=4; Path=/foo; \ diff --git a/actix-http/src/header/shared/httpdate.rs b/actix-http/src/header/shared/httpdate.rs index b0ef64a08..90ac13d70 100644 --- a/actix-http/src/header/shared/httpdate.rs +++ b/actix-http/src/header/shared/httpdate.rs @@ -18,11 +18,11 @@ impl FromStr for HttpDate { type Err = ParseError; fn from_str(s: &str) -> Result { - match OffsetDateTime::parse(s, "%a, %d %b %Y %H:%M:%S") - .or_else(|_| OffsetDateTime::parse(s, "%A, %d-%b-%y %H:%M:%S")) - .or_else(|_| OffsetDateTime::parse(s, "%c")) + match PrimitiveDateTime::parse(s, "%a, %d %b %Y %H:%M:%S") + .or_else(|_| PrimitiveDateTime::parse(s, "%A, %d-%b-%y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(s, "%c")) { - Ok(t) => Ok(HttpDate(t)), + Ok(t) => Ok(HttpDate(t.using_offset(UtcOffset::UTC))), Err(_) => { Err(ParseError::Header) },