fixed write header bug in case of errors in index html (#4185)

This commit is contained in:
Aziz Rmadi
2025-01-30 21:21:51 -08:00
committed by GitHub
parent 8913779f81
commit 8af820e60e
+7 -1
View File
@@ -108,9 +108,15 @@ func renderIndexHtml(w http.ResponseWriter, nonce string) {
return 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) http.Error(w, err.Error(), http.StatusInternalServerError)
return
} }
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buf.Bytes())
} }
// MetadataPage represents a server-rendered web page for bots and web scrapers. // MetadataPage represents a server-rendered web page for bots and web scrapers.