1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

fileserver: Remove newline characters from precomputed etags (#6394)

* Removed newline characters from precomputed etags

* Update modules/caddyhttp/fileserver/staticfiles.go

---------

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
Aziz Rmadi 2024-06-19 08:27:10 -05:00 committed by GitHub
parent 99dcdf7e42
commit c2ccf8690f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,7 @@
package fileserver package fileserver
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -690,6 +691,10 @@ func (fsrv *FileServer) getEtagFromFile(fileSystem fs.FS, filename string) (stri
if err != nil { if err != nil {
return "", fmt.Errorf("cannot read etag from file %s: %v", etagFilename, err) return "", fmt.Errorf("cannot read etag from file %s: %v", etagFilename, err)
} }
// Etags should not contain newline characters
etag = bytes.ReplaceAll(etag, []byte("\n"), []byte{})
return string(etag), nil return string(etag), nil
} }
return "", nil return "", nil