summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2023-05-22 14:17:15 -0600
committerGitHub <noreply@github.com>2023-05-22 14:17:15 -0600
commit5bd9c49042112183f0902a7ce6252aebf58e1ac9 (patch)
tree35a70350c6bcb4487c660c8a925fc19ee3acffcb /modules/caddyhttp
parentcdd3884b32e7e8194cb0b753389b5e6aa34ac836 (diff)
fileserver: Don't set Etag if mtime is 0 or 1 (close #5548) (#5550)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index feef66d..f335d31 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -616,7 +616,11 @@ func (fsrv *FileServer) notFound(w http.ResponseWriter, r *http.Request, next ca
// Prefix the etag with "W/" to convert it into a weak etag.
// See: https://tools.ietf.org/html/rfc7232#section-2.3
func calculateEtag(d os.FileInfo) string {
- t := strconv.FormatInt(d.ModTime().Unix(), 36)
+ mtime := d.ModTime().Unix()
+ if mtime == 0 || mtime == 1 {
+ return "" // not useful anyway; see issue #5548
+ }
+ t := strconv.FormatInt(mtime, 36)
s := strconv.FormatInt(d.Size(), 36)
return `"` + t + s + `"`
}