···
mimeType = "image/svg+xml"
289
+
contentHash := sha256.Sum256(contents)
290
+
eTag := fmt.Sprintf("\"%x\"", contentHash)
// allow image, video, and text/plain files to be served directly
291
-
case strings.HasPrefix(mimeType, "image/"):
293
-
case strings.HasPrefix(mimeType, "video/"):
294
+
case strings.HasPrefix(mimeType, "image/"), strings.HasPrefix(mimeType, "video/"):
295
+
if clientETag := r.Header.Get("If-None-Match"); clientETag == eTag {
296
+
w.WriteHeader(http.StatusNotModified)
299
+
w.Header().Set("ETag", eTag)
case strings.HasPrefix(mimeType, "text/plain"):
302
+
w.Header().Set("Cache-Control", "public, no-cache")
l.Error("attempted to serve disallowed file type", "mimetype", mimeType)
writeError(w, "only image, video, and text files can be accessed directly", http.StatusForbidden)
303
-
w.Header().Set("Cache-Control", "public, max-age=86400") // cache for 24 hours
304
-
w.Header().Set("ETag", fmt.Sprintf("%x", sha256.Sum256(contents)))
w.Header().Set("Content-Type", mimeType)