refactor: replace HasSuffix+TrimSuffix with CutSuffix

Signed-off-by: ledigang <shuangcui@msn.com>
This commit is contained in:
ledigang 2025-11-20 16:46:08 +08:00
parent eead249382
commit f40d82d44c

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)
}
}