1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-05-13 10:34:44 +00:00

Add ETag for access file ()

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks 2024-07-09 16:58:35 +08:00 committed by GitHub
parent 4ca723d183
commit 49168a140c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions
fileserver
server

View File

@ -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")

View File

@ -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;
}