fix: re-apply initial fix + set content-type header. Fixes #4114

This commit is contained in:
Gabe Kangas
2025-02-23 17:46:16 -08:00
parent 3853a649e0
commit f0650ce760
+8 -1
View File
@@ -108,9 +108,16 @@ func renderIndexHtml(w http.ResponseWriter, nonce string) {
return
}
if err := index.Execute(w, content); err != nil {
// Use a buffer to ensure that we do not write a partial response header before checking for errors
var buf bytes.Buffer
if err := index.Execute(&buf, content); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buf.Bytes())
}
// MetadataPage represents a server-rendered web page for bots and web scrapers.