fix: do not use ETag for robots.txt

robots.txt file does not change over time, so adding a tag is not required.
This commit is contained in:
Evsyukov Denis 2024-04-12 09:31:06 +03:00
parent 54cda5546a
commit 3799e87a70
No known key found for this signature in database

View File

@ -167,19 +167,13 @@ func handlerStyle(w http.ResponseWriter, rq *http.Request) {
func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) { func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Header().Set("Content-Type", "text/plain; charset=utf-8")
hash := md5.New()
file, err := static.FS.Open("robots.txt") file, err := static.FS.Open("robots.txt")
if err != nil { if err != nil {
return return
} }
_, err = io.Copy(hash, file)
if err != nil {
log.Println(err)
}
w.Header().Set("ETag", hex.EncodeToString(hash.Sum(nil)))
_, err = io.Copy(w, file) _, err = io.Copy(w, file)
if err != nil { if err != nil {
log.Println(err) log.Println()
} }
_ = file.Close() _ = file.Close()
} }