From 712cc328e131793677d6fa034f99998e16ad6f99 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 7 Oct 2023 03:25:43 +0200 Subject: [PATCH] fetch, send: use httpdate for formatting Date: header > Oct 07 03:25:59 buzzrelay buzzrelay[676]: 2023-10-07T01:25:59.381211Z ERROR buzzrelay::relay: relay::send Response("{\"error\":\"Invalid Date header: not RFC 2616 compliant date: \\\"Sat, 7 Oct 2023 01:25:58 GMT\\\"\"}") is it the leading 0 in the day position? --- Cargo.lock | 1 + Cargo.toml | 1 + src/fetch.rs | 4 ++-- src/send.rs | 5 ++--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4281c6d..6021492 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,6 +283,7 @@ dependencies = [ "futures", "http", "http_digest_headers", + "httpdate", "metrics", "metrics-exporter-prometheus", "metrics-util", diff --git a/Cargo.toml b/Cargo.toml index 3470e03..3888675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,4 @@ metrics-util = "0.15" metrics-exporter-prometheus = "0.12" deunicode = "1.3" urlencoding = "2" +httpdate = "1" diff --git a/src/fetch.rs b/src/fetch.rs index 2387c41..9cfb74a 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -1,3 +1,4 @@ +use std::time::SystemTime; use http::StatusCode; use serde::de::DeserializeOwned; use sigh::{PrivateKey, SigningConfig, alg::RsaSha256}; @@ -21,8 +22,7 @@ where .uri(uri) .header("host", &host) .header("content-type", "application/activity+json") - .header("date", chrono::Utc::now().to_rfc2822() - .replace("+0000", "GMT")) + .header("date", httpdate::fmt_http_date(SystemTime::now())) .header("accept", "application/activity+json") .header("digest", digest_header) .body(vec![])?; diff --git a/src/send.rs b/src/send.rs index 9c07a7d..c94b919 100644 --- a/src/send.rs +++ b/src/send.rs @@ -1,6 +1,6 @@ use std::{ sync::Arc, - time::Instant, + time::{Instant, SystemTime}, }; use http::StatusCode; use metrics::histogram; @@ -39,8 +39,7 @@ pub async fn send_raw( .uri(uri) .header("host", &host) .header("content-type", "application/activity+json") - .header("date", chrono::Utc::now().to_rfc2822() - .replace("+0000", "GMT")) + .header("date", httpdate::fmt_http_date(SystemTime::now())) .header("digest", digest_header) .body(body.as_ref().clone()) .map_err(Error::HttpReq)?;