From 85b5c2be89e942d75191db58c51003c4a0e23210 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. --- web/planet-mars/src/feed_store.rs | 4 ++-- web/planet-mars/src/fetcher.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/planet-mars/src/feed_store.rs b/web/planet-mars/src/feed_store.rs index 7b75e5164..8b9cba3e5 100644 --- a/web/planet-mars/src/feed_store.rs +++ b/web/planet-mars/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/web/planet-mars/src/fetcher.rs b/web/planet-mars/src/fetcher.rs index 13c326f8a..bb982698b 100644 --- a/web/planet-mars/src/fetcher.rs +++ b/web/planet-mars/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();