encode: modernize, replace HasSuffix+TrimSuffix with CutSuffix (#7357)

Signed-off-by: ledigang <shuangcui@msn.com>
This commit is contained in:
ledigang 2025-11-22 06:30:26 +08:00 committed by GitHub
parent b9e6f3b227
commit 2cb426776c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,8 +168,8 @@ func (enc *Encode) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyh
// caches without knowing about our changes...
if etag := r.Header.Get("If-None-Match"); etag != "" && !strings.HasPrefix(etag, "W/") {
ourSuffix := "-" + encName + `"`
if strings.HasSuffix(etag, ourSuffix) {
etag = strings.TrimSuffix(etag, ourSuffix) + `"`
if before, ok := strings.CutSuffix(etag, ourSuffix); ok {
etag = before + `"`
r.Header.Set("If-None-Match", etag)
}
}