From 3389292457d4584d28c65e3f3db61f5f736f750b Mon Sep 17 00:00:00 2001 From: _ <> Date: Sat, 3 Apr 2021 15:53:59 +0000 Subject: [PATCH] placeholder for caching - Always returns a random ETag header. So the browser-side cache will always miss, but I tested that Firefox will at least send us If-None-Match with the last ETag it saw. --- crates/ptth_server/src/file_server/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/ptth_server/src/file_server/mod.rs b/crates/ptth_server/src/file_server/mod.rs index 291e9e4..3f70878 100644 --- a/crates/ptth_server/src/file_server/mod.rs +++ b/crates/ptth_server/src/file_server/mod.rs @@ -189,6 +189,21 @@ async fn serve_file ( let mut response = Response::default (); + // The cache-related headers in HTTP have bad names. See here: + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control + // The intended semantics I'm using are: + // - etag - Some random hashed value that changes whenever the metadata + // (name, inode number, length, mtime) of a file changes. Also changes + // on new server instance. + // - no-cache - Clients and the relay can store this, but should revalidate + // with the origin server (us) because only we can check if the file + // changed on disk. + // - max-age=0 - The file might change at any point during or after the + // request, so for proper invalidation, the client should immediately + // consider it stale. + + response.header ("cache-control".to_string (), b"no-cache,max-age=0".to_vec ()); + response.header ("etag".to_string (), rusty_ulid::generate_ulid_string ().into_bytes ()); response.header (String::from ("accept-ranges"), b"bytes".to_vec ()); if range_requested {