Skip to content

Commit

Permalink
Update cookie crates (seanmonstar#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored Jun 24, 2020
1 parent 1c68000 commit f2e8dd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ tokio-rustls = { version = "0.13", optional = true }
webpki-roots = { version = "0.19", optional = true }

## cookies
cookie_crate = { version = "0.12", package = "cookie", optional = true }
cookie_store = { version = "0.11", optional = true }
time = { version = "0.1.42", optional = true }
cookie_crate = { version = "0.14", package = "cookie", optional = true }
cookie_store = { version = "0.12", optional = true }
time = { version = "0.2.11", optional = true }

## compression
async-compression = { version = "0.3.0", default-features = false, features = ["stream"], optional = true }
Expand Down
17 changes: 4 additions & 13 deletions src/cookie.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! HTTP Cookies
use std::convert::TryInto;

use crate::header;
use std::fmt;
use std::time::SystemTime;
Expand Down Expand Up @@ -64,12 +66,12 @@ impl<'a> Cookie<'a> {
pub fn max_age(&self) -> Option<std::time::Duration> {
self.0
.max_age()
.map(|d| std::time::Duration::new(d.num_seconds() as u64, 0))
.map(|d| d.try_into().expect("time::Duration into std::time::Duration"))
}

/// The cookie expiration time.
pub fn expires(&self) -> Option<SystemTime> {
self.0.expires().map(tm_to_systemtime)
self.0.expires().map(SystemTime::from)
}
}

Expand Down Expand Up @@ -98,17 +100,6 @@ impl<'a> fmt::Debug for CookieStore {
}
}

/// Convert a time::Tm time to SystemTime.
fn tm_to_systemtime(tm: time::Tm) -> SystemTime {
let seconds = tm.to_timespec().sec;
let duration = std::time::Duration::from_secs(seconds.abs() as u64);
if seconds > 0 {
SystemTime::UNIX_EPOCH + duration
} else {
SystemTime::UNIX_EPOCH - duration
}
}

/// Error representing a parse failure of a 'Set-Cookie' header.
pub(crate) struct CookieParseError(cookie_crate::ParseError);

Expand Down

0 comments on commit f2e8dd2

Please sign in to comment.