Actually end the connection when request checks fail
This commit is contained in:
parent
7ac8e91cc2
commit
cf9678d712
3 changed files with 26 additions and 23 deletions
|
|
@ -16,14 +16,17 @@ func StateOpen(
|
|||
resp *types.SpaceState,
|
||||
) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
body := string(updateEndpointValidator(authDB, validCredentials, w, r))
|
||||
body, err := updateEndpointValidator(authDB, validCredentials, w, r)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse request body
|
||||
newState, err := strconv.ParseBool(body)
|
||||
newState, err := strconv.ParseBool(string(body))
|
||||
if err != nil {
|
||||
log.Println("Failed to parse request body from", r.RemoteAddr, "body:", body)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, _ = io.WriteString(w, "HTTP request body should either be true or false")
|
||||
log.Println("Failed to parse request body from", r.RemoteAddr, "with error:", err)
|
||||
http.Error(w, "HTTP request body should either be true or false", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue