Skip to content

Commit fefb720

Browse files
authored
Merge pull request #1 from csoni111/cache-bug
Add cache-control header in api response
2 parents 387e37c + e52fe13 commit fefb720

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/fs/service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func directory(fi os.FileInfo, js string, w http.ResponseWriter, request *http.R
165165
w.Header().Set("Content-Length", strconv.FormatInt(size, 10))
166166
w.Header().Set("Last-Modified", fi.ModTime().UTC().Format(http.TimeFormat))
167167
w.Header().Set("Content-Type", "application/json")
168+
w.Header().Set("Cache-Control", "max-age=0, private, must-revalidate")
168169
w.WriteHeader(http.StatusOK)
169170
w.Write(json)
170171
status = 200
@@ -266,6 +267,7 @@ func (service *MercuryFsService) serve_file(writer http.ResponseWriter, request
266267
} else {
267268
writer.Header().Set("Last-Modified", mtime)
268269
writer.Header().Set("ETag", etag)
270+
writer.Header().Set("Cache-Control", "max-age=0, private, must-revalidate")
269271
debug(4, "Etag sent: %s", etag)
270272
http.ServeContent(writer, request, full_path, fi.ModTime(), osFile)
271273
log("\"GET %s\" %d %d \"%s\"", query, 200, fi.Size(), ua)
@@ -293,6 +295,7 @@ func (service *MercuryFsService) serve_shares(writer http.ResponseWriter, reques
293295
writer.Header().Set("Last-Modified", service.Shares.LastChecked.Format(http.TimeFormat))
294296
writer.Header().Set("ETag", etag)
295297
writer.Header().Set("Content-Type", "application/json")
298+
writer.Header().Set("Cache-Control", "max-age=0, private, must-revalidate")
296299
writer.WriteHeader(http.StatusOK)
297300
writer.Write([]byte(json))
298301
service.debug_info.requestServed(size)
@@ -407,6 +410,7 @@ func (service *MercuryFsService) apps_list(writer http.ResponseWriter, request *
407410
writer.Header().Set("Content-Length", strconv.FormatInt(size, 10))
408411
writer.Header().Set("ETag", etag)
409412
writer.Header().Set("Content-Type", "application/json")
413+
writer.Header().Set("Cache-Control", "max-age=0, private, must-revalidate")
410414
writer.WriteHeader(http.StatusOK)
411415
writer.Write([]byte(json))
412416
service.debug_info.requestServed(size)
@@ -451,6 +455,7 @@ func (service *MercuryFsService) get_metadata(writer http.ResponseWriter, reques
451455
writer.Header().Set("Content-Length", strconv.FormatInt(size, 10))
452456
writer.Header().Set("ETag", etag)
453457
writer.Header().Set("Content-Type", "application/json")
458+
writer.Header().Set("Cache-Control", "max-age=0, private, must-revalidate")
454459
writer.WriteHeader(http.StatusOK)
455460
writer.Write([]byte(json))
456461
service.debug_info.requestServed(size)

0 commit comments

Comments
 (0)