summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorCharles Duffy <charles@dyfis.net>2023-05-20 18:21:43 -0500
committerGitHub <noreply@github.com>2023-05-20 17:21:43 -0600
commit2615c9c52417d6ac01a56841b4684400b33f7db1 (patch)
treec37b2d2c4e704155c347dcb4337fcc88f80b008b /modules/caddyhttp
parent5336bc0fb623c1293c2d93571d47dff58863f1c1 (diff)
fileserver: Only set Etag if not already set (fix #5546) (#5547)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index 2b5cc3d..feef66d 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -356,7 +356,9 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
}
var file fs.File
- var etag string
+
+ // etag is usually unset, but if the user knows what they're doing, let them override it
+ etag := w.Header().Get("Etag")
// check for precompressed files
for _, ae := range encode.AcceptedEncodings(r, fsrv.PrecompressedOrder) {
@@ -388,7 +390,9 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
// don't assign info = compressedInfo because sidecars are kind
// of transparent; however we do need to set the Etag:
// https://caddy.community/t/gzipped-sidecar-file-wrong-same-etag/16793
- etag = calculateEtag(compressedInfo)
+ if etag == "" {
+ etag = calculateEtag(compressedInfo)
+ }
break
}
@@ -408,7 +412,9 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
}
defer file.Close()
- etag = calculateEtag(info)
+ if etag == "" {
+ etag = calculateEtag(info)
+ }
}
// at this point, we're serving a file; Go std lib supports only
@@ -421,7 +427,9 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
// set the Etag - note that a conditional If-None-Match request is handled
// by http.ServeContent below, which checks against this Etag value
- w.Header().Set("Etag", etag)
+ if etag != "" {
+ w.Header().Set("Etag", etag)
+ }
if w.Header().Get("Content-Type") == "" {
mtyp := mime.TypeByExtension(filepath.Ext(filename))