Skip to content

Commit

Permalink
Add comment and set no-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Sep 3, 2024
1 parent b50da91 commit 99dc7ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 2 additions & 9 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, "")

Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions server/access-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1882,6 +1893,7 @@ get_form_field (const char *body_str, const char *field_name)
g_free (value);
return result;
}
*/

/*
static void
Expand Down

0 comments on commit 99dc7ab

Please sign in to comment.