Parcourir la source

control: fix body rejection guard for empty POST requests

rejectBody() returns true when the request body is acceptable and false when a body must be rejected. The TX and fault-reset handlers treated the return value the wrong way around and returned early on valid empty POST requests. This prevented actions like /tx/stop from running in the normal no-body case.

Update the handlers to only abort when rejectBody() reports an actual rejection, so empty POST control actions proceed as intended.
main
Jan il y a 1 mois
Parent
révision
1d683d1d8f
1 fichiers modifiés avec 5 ajouts et 2 suppressions
  1. +5
    -2
      internal/control/control.go

+ 5
- 2
internal/control/control.go Voir le fichier

@@ -155,12 +155,15 @@ func hasRequestBody(r *http.Request) bool {
}

func (s *Server) rejectBody(w http.ResponseWriter, r *http.Request) bool {
// Returns true when the request has an unexpected body and the error response
// has already been written — callers should return immediately in that case.
// Returns false when there is no body (happy path — request should proceed).
if !hasRequestBody(r) {
return true
return false
}
s.recordAudit(auditUnexpectedBody)
http.Error(w, noBodyErrMsg, http.StatusBadRequest)
return false
return true
}

func (s *Server) recordAudit(evt auditEvent) {


Chargement…
Annuler
Enregistrer