From 49168a140ccaccc66026f0a288684fc7fafbc17a Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:58:35 +0800 Subject: [PATCH] Add ETag for access file (#664) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 杨赫然 --- fileserver/fileop.go | 1 + server/access-file.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/fileserver/fileop.go b/fileserver/fileop.go index 8e5e9623..38b684a5 100644 --- a/fileserver/fileop.go +++ b/fileserver/fileop.go @@ -149,6 +149,7 @@ func accessCB(rsp http.ResponseWriter, r *http.Request) *appError { } now := time.Now() + rsp.Header().Set("ETag", objID) rsp.Header().Set("Last-Modified", now.Format("Mon, 2 Jan 2006 15:04:05 GMT")) rsp.Header().Set("Cache-Control", "max-age=3600") diff --git a/server/access-file.c b/server/access-file.c index 54b339bb..8641ffe1 100644 --- a/server/access-file.c +++ b/server/access-file.c @@ -1110,6 +1110,16 @@ start_download_zip_file (evhtp_request_t *req, const char *token, return 0; } +static void +set_etag (evhtp_request_t *req, + const char *file_id) +{ + evhtp_kv_t *kv; + + kv = evhtp_kv_new ("ETag", file_id, 1, 1); + evhtp_kvs_add_kv (req->headers_out, kv); +} + static gboolean can_use_cached_content (evhtp_request_t *req) { @@ -1300,6 +1310,8 @@ access_cb(evhtp_request_t *req, void *arg) goto on_error; } + set_etag (req, data); + if (can_use_cached_content (req)) { goto success; }