Skip to content

Commit

Permalink
Add ETag for access file (#664)
Browse files Browse the repository at this point in the history
Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Jul 9, 2024
1 parent 4ca723d commit 49168a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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

0 comments on commit 49168a1

Please sign in to comment.