Buffer the login page so HEAD requests skip the body write

This commit is contained in:
Ian Gulliver
2026-08-20 12:59:47 -07:00
parent 7fd198e75e
commit 366e120a05
+7 -1
View File
@@ -2,6 +2,7 @@
package auth package auth
import ( import (
"bytes"
"context" "context"
"crypto/hmac" "crypto/hmac"
"crypto/sha256" "crypto/sha256"
@@ -95,13 +96,18 @@ func (a *Auth) loginPage(w http.ResponseWriter, r *http.Request) {
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" { if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
scheme = "https" scheme = "https"
} }
err = t.Execute(w, map[string]string{ var page bytes.Buffer
err = t.Execute(&page, map[string]string{
"ClientID": a.clientID, "ClientID": a.clientID,
"LoginURI": scheme + "://" + r.Host + "/auth/login", "LoginURI": scheme + "://" + r.Host + "/auth/login",
}) })
if err != nil { if err != nil {
log.Printf("[ERROR] render login page: %v", err) log.Printf("[ERROR] render login page: %v", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
} }
w.Header().Set("Content-Type", "text/html; charset=utf-8")
http.ServeContent(w, r, "", time.Time{}, bytes.NewReader(page.Bytes()))
} }
func (a *Auth) login(w http.ResponseWriter, r *http.Request) { func (a *Auth) login(w http.ResponseWriter, r *http.Request) {