mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-12 02:28:51 +00:00
fix: tolerate empty body on job rejection endpoint
The reject job handler should accept nil/empty bodies (no reason given) while still rejecting malformed JSON. Check for io.EOF and http.NoBody to distinguish missing body from invalid body. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -185,8 +186,8 @@ func (h JobHandler) RejectJob(w http.ResponseWriter, r *http.Request) {
|
|||||||
var body struct {
|
var body struct {
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
}
|
}
|
||||||
if r.Body != nil {
|
if r.Body != nil && r.Body != http.NoBody {
|
||||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil && err != io.EOF {
|
||||||
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid request body", requestID)
|
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid request body", requestID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user