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 {