Skip to content

chore: upgrade time crate #6271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE

## Unreleased

- The HTTP `Date` header in responses now strictly follows RFC7231.

### Changed

- When a previous block commit is unable to be RBFed, the miner will now just wait for it to be confirmed instead of submitting a new block commit which breaks the miner's UTXO chain.
Expand Down
38 changes: 18 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions clarity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ rusqlite = { workspace = true, optional = true }
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]

[dependencies.time]
version = "0.2.23"
features = ["std"]

[dev-dependencies]
assert-json-diff = "1.0.0"
mutants = "0.0.3"
Expand Down
4 changes: 0 additions & 4 deletions stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ workspace = true
version = "4.1.3"
features = ["serde"]

[dependencies.time]
version = "0.2.23"
features = ["std"]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
secp256k1 = { version = "0.24.3", features = ["serde", "recovery"] }

Expand Down
4 changes: 2 additions & 2 deletions stacks-common/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub mod vrf;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{error, fmt, thread, time};
use std::time::{self, SystemTime, UNIX_EPOCH};
use std::{error, fmt, thread};

/// Given a relative path inside the Cargo workspace, return the absolute path
#[cfg(any(test, feature = "testing"))]
Expand Down
5 changes: 1 addition & 4 deletions stackslib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ libstackerdb = { path = "../libstackerdb" }
siphasher = "0.3.7"
hashbrown = { workspace = true }
rusqlite = { workspace = true }
time = "0.3.41"
toml = { workspace = true }

[target.'cfg(not(any(target_os = "macos",target_os="windows", target_arch = "arm" )))'.dependencies]
Expand All @@ -77,10 +78,6 @@ features = ["serde", "recovery"]
[dependencies.ed25519-dalek]
workspace = true

[dependencies.time]
version = "0.2.23"
features = ["std"]

[dev-dependencies]
assert-json-diff = "1.0.0"
stdext = "0.3.1"
Expand Down
11 changes: 6 additions & 5 deletions stackslib/src/net/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::collections::{BTreeMap, HashSet};
use std::fmt;
use std::io::{Read, Write};
use std::time::SystemTime;

use stacks_common::codec::{Error as CodecError, StacksMessageCodec};
use stacks_common::deps_common::httparse;
Expand Down Expand Up @@ -347,9 +346,11 @@ impl HttpResponsePreamble {
}

/// Get an RFC 7231 date that represents the current time
fn rfc7231_now() -> String {
let now = time::PrimitiveDateTime::from(SystemTime::now());
now.format("%a, %b %-d %-Y %-H:%M:%S GMT")
fn rfc7231_now() -> Result<String, CodecError> {
time::OffsetDateTime::now_utc()
.format(&time::format_description::well_known::Rfc2822)
.map(|date| date.replace("+0000", "GMT"))
.map_err(|e| CodecError::GenericError(format!("Failed to format RFC 7231 date: {:?}", e)))
}

/// Read from a stream until we see '\r\n\r\n', with the purpose of reading an HTTP preamble.
Expand Down Expand Up @@ -387,7 +388,7 @@ impl StacksMessageCodec for HttpResponsePreamble {
if !self.headers.contains_key("date") {
fd.write_all("Date: ".as_bytes())
.map_err(CodecError::WriteError)?;
fd.write_all(rfc7231_now().as_bytes())
fd.write_all(rfc7231_now()?.as_bytes())
.map_err(CodecError::WriteError)?;
fd.write_all("\r\n".as_bytes())
.map_err(CodecError::WriteError)?;
Expand Down
11 changes: 10 additions & 1 deletion stackslib/src/net/http/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::collections::BTreeMap;

use regex;
use stacks_common::codec::{Error as CodecError, StacksMessageCodec};
use stacks_common::types::net::{PeerAddress, PeerHost};

Expand Down Expand Up @@ -146,7 +147,7 @@ fn test_parse_http_request_preamble_ok() {
("POST asdf HTTP/1.1\r\nHost: core.blockstack.org\r\nConnection: close\r\nFoo: Bar\r\n\r\n",
HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()])),
("POST asdf HTTP/1.1\r\nHost: core.blockstack.org\r\nFoo: Bar\r\nConnection: close\r\n\r\n",
HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()]))
HttpRequestPreamble::from_headers(HttpVersion::Http11, "POST".to_string(), "asdf".to_string(), "core.blockstack.org".to_string(), 80, false, vec!["foo".to_string()], vec!["Bar".to_string()]))
];

for (data, request) in tests.iter() {
Expand Down Expand Up @@ -391,6 +392,14 @@ fn test_http_response_preamble_headers() {
"Content-Type is missing"
);
assert!(txt.find("Date: ").is_some(), "Date header is missing");

let rfc7231_date_regex =
regex::Regex::new(r"Date: [A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n")
.unwrap();
assert!(
rfc7231_date_regex.is_match(&txt),
"Date header format is incorrect"
);
assert!(txt.find("foo: bar\r\n").is_some(), "foo header is missing");
assert!(
txt.find("Access-Control-Allow-Origin: *\r\n").is_some(),
Expand Down
Loading