Buffer the login page so HEAD requests skip the body write
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user