Skip to content

Commit

Permalink
Remove chrono, use time directly, due to RUSTSEC-2020-0159
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Jan 9, 2022
1 parent 9a2566c commit 2975190
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -19,8 +19,8 @@ ascii = "1.0"
chunked_transfer = "1"
openssl = { version = "0.10", optional = true }
url = "2"
chrono = { version = "0.4", default-features = false, features=["clock"] }
log = "0.4"
time = { version = "0.3", features = [ "std", "formatting" ] }

[dev-dependencies]
rustc-serialize = "0.3"
Expand Down
16 changes: 11 additions & 5 deletions src/common.rs
Expand Up @@ -2,8 +2,7 @@ use ascii::{AsciiStr, AsciiString, FromAsciiError};
use std::cmp::Ordering;
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use chrono::*;
use time::{format_description, OffsetDateTime};

/// Status code of a request or response.
#[derive(Eq, PartialEq, Copy, Clone, Debug, Ord, PartialOrd)]
Expand Down Expand Up @@ -398,18 +397,25 @@ impl From<(u8, u8)> for HTTPVersion {
/// Represents the current date, expressed in RFC 1123 format, e.g. Sun, 06 Nov 1994 08:49:37 GMT
#[allow(clippy::upper_case_acronyms)]
pub struct HTTPDate {
d: DateTime<Utc>,
d: OffsetDateTime,
}

impl HTTPDate {
pub fn new() -> HTTPDate {
HTTPDate { d: Utc::now() }
HTTPDate {
d: OffsetDateTime::now_utc(),
}
}
}

impl ToString for HTTPDate {
fn to_string(&self) -> String {
self.d.format("%a, %e %b %Y %H:%M:%S GMT").to_string()
// Note: This can probably be made Self::format however parse is not a const function, making this difficult.
let format = format_description::parse("%a, %e %b %Y %H:%M:%S GMT")
.expect("Cannot fail. The format string is correct.");
self.d
.format(&format)
.expect("Cannot fail with this format under any reasonable conditions.")
}
}

Expand Down

0 comments on commit 2975190

Please sign in to comment.