From 4a58996e44bf0dc53c0a2a372361cd0590399ca1 Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Sat, 11 Jan 2025 13:38:20 +0200 Subject: [PATCH] Fix caching Nginx's std cfg only returns 304 with If-Unmodified-Since header, if the date is exactly the one it expects, not the date the client did its last request. This makes sense as it is much easier to compare two strings for equality than to parse the date received from the client and check the ordering with the server known last_modified value. --- src/feed_store.rs | 4 ++-- src/fetcher.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/feed_store.rs b/src/feed_store.rs index 7b75e51..8b9cba3 100644 --- a/src/feed_store.rs +++ b/src/feed_store.rs @@ -13,7 +13,7 @@ use url::Url; #[derive(Deserialize, Serialize, Default)] pub struct FetchData { pub etag: String, - pub date: String, + pub last_modified: String, } pub struct FeedStore { @@ -81,7 +81,7 @@ impl FeedStore { let headers = response.headers(); let fetchdata = FetchData { etag: hv(headers, "etag"), - date: hv(headers, "date"), + last_modified: hv(headers, "last_modified"), }; let body = response diff --git a/src/fetcher.rs b/src/fetcher.rs index 13c326f..bb98269 100644 --- a/src/fetcher.rs +++ b/src/fetcher.rs @@ -40,8 +40,8 @@ impl Fetcher { if !fetchdata.etag.is_empty() { builder = builder.header("If-None-Match", fetchdata.etag); } - if !fetchdata.date.is_empty() { - builder = builder.header("If-Modified-Since", fetchdata.date); + if !fetchdata.last_modified.is_empty() { + builder = builder.header("If-Modified-Since", fetchdata.last_modified); } let start_instant = Instant::now();