From 99dc7ab1046b2f47aa9a251ad33d1a14858db0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB=E7=84=B6?= Date: Tue, 3 Sep 2024 17:06:31 +0800 Subject: [PATCH] Add comment and set no-cache --- fileserver/fileop.go | 11 ++--------- server/access-file.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/fileserver/fileop.go b/fileserver/fileop.go index e47b30ed..e8013d47 100644 --- a/fileserver/fileop.go +++ b/fileserver/fileop.go @@ -643,10 +643,6 @@ func doBlock(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, fileI } func accessZipCB(rsp http.ResponseWriter, r *http.Request) *appError { - if seahubPK == "" { - err := fmt.Errorf("no seahub private key is configured") - return &appError{err, "", http.StatusNotFound} - } parts := strings.Split(r.URL.Path[1:], "/") if len(parts) != 2 { msg := "Invalid URL" @@ -3570,10 +3566,6 @@ func accessLinkCB(rsp http.ResponseWriter, r *http.Request) *appError { fileName := filepath.Base(filePath) op := "download-link" - if _, ok := r.Header["If-Modified-Since"]; ok { - return &appError{nil, "", http.StatusNotModified} - } - ranges := r.Header["Range"] byteRanges := strings.Join(ranges, "") @@ -3591,13 +3583,14 @@ func accessLinkCB(rsp http.ResponseWriter, r *http.Request) *appError { return &appError{nil, msg, http.StatusBadRequest} } + // Check for file changes by comparing the ETag in the If-None-Match header with the file ID. Set no-cache to allow clients to validate file changes before using the cache. etag := r.Header.Get("If-None-Match") if etag == fileID { return &appError{nil, "", http.StatusNotModified} } rsp.Header().Set("ETag", fileID) - rsp.Header().Set("Cache-Control", "no-chche") + rsp.Header().Set("Cache-Control", "no-cache") var cryptKey *seafileCrypt if repo.IsEncrypted { diff --git a/server/access-file.c b/server/access-file.c index ce2e68cb..b36a2c4a 100644 --- a/server/access-file.c +++ b/server/access-file.c @@ -1119,6 +1119,15 @@ set_etag (evhtp_request_t *req, evhtp_kvs_add_kv (req->headers_out, kv); } +static void +set_no_cache (evhtp_request_t *req) +{ + evhtp_kv_t *kv; + + kv = evhtp_kv_new ("Cache-Control", "no-cache", 1, 1); + evhtp_kvs_add_kv (req->headers_out, kv); +} + static gboolean can_use_cached_content (evhtp_request_t *req) { @@ -1720,6 +1729,7 @@ access_link_cb(evhtp_request_t *req, void *arg) goto out; } set_etag (req, file_id); + set_no_cache (req); byte_ranges = evhtp_kv_find (req->headers_in, "Range"); @@ -1772,6 +1782,7 @@ access_link_cb(evhtp_request_t *req, void *arg) } } +/* static GList * json_to_dirent_list (SeafRepo *repo, const char *parent_dir, const char *dirents) { @@ -1882,6 +1893,7 @@ get_form_field (const char *body_str, const char *field_name) g_free (value); return result; } +*/ /* static void