cpolis/cmd/frontend/notifications.go

21 lines
460 B
Go

package frontend
import (
"fmt"
"html/template"
"net/http"
)
func notifyClient(w http.ResponseWriter, message string, status int) {
h := w.Header()
h.Del("Content-Length")
h.Set("Content-Type", "text/html; charset=utf-8")
if status >= 400 {
h.Set("X-Content-Type-Options", "nosniff")
}
w.WriteHeader(status)
safeMsg := template.HTMLEscapeString(message)
fmt.Fprintf(w, `<span id="notification-content" hx-swap-oob="true">%s</span>`, safeMsg)
}