mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 21:53:48 +03:00
fileserver: Better fix for Etag of compressed files
This commit is contained in:
parent
8c72f34357
commit
7ab61f46f0
1 changed files with 13 additions and 4 deletions
|
@ -351,6 +351,7 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
}
|
||||
|
||||
var file fs.File
|
||||
var etag string
|
||||
|
||||
// check for precompressed files
|
||||
for _, ae := range encode.AcceptedEncodings(r, fsrv.PrecompressedOrder) {
|
||||
|
@ -371,13 +372,19 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
if caddyErr, ok := err.(caddyhttp.HandlerError); ok && caddyErr.StatusCode == http.StatusServiceUnavailable {
|
||||
return err
|
||||
}
|
||||
file = nil
|
||||
continue
|
||||
}
|
||||
defer file.Close()
|
||||
info = compressedInfo
|
||||
w.Header().Set("Content-Encoding", ae)
|
||||
w.Header().Del("Accept-Ranges")
|
||||
w.Header().Add("Vary", "Accept-Encoding")
|
||||
|
||||
// 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)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -395,11 +402,13 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||
return err // error is already structured
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
etag = calculateEtag(info)
|
||||
}
|
||||
|
||||
// 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", calculateEtag(info))
|
||||
// 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 w.Header().Get("Content-Type") == "" {
|
||||
mtyp := mime.TypeByExtension(filepath.Ext(filename))
|
||||
|
|
Loading…
Reference in a new issue