Skip to content

Commit 0e3e563

Browse files
committed
http: allow empty request bodies in JSON parsing
The JSON decoder returns io.EOF when the request body is empty, which was previously treated as an error. This prevented API endpoints with optional request bodies from succeeding when called without a body. Treat io.EOF as an empty object to support endpoints like DELETE /sys/rekey/init that accept either a body with parameters or no body at all. Signed-off-by: Tero Saarni <[email protected]>
1 parent 46b1821 commit 0e3e563

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

changelog/31650.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
http: allow empty request bodies in JSON parsing
3+
```

http/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,10 @@ func parseJSONRequest(perfStandby bool, r *http.Request, w http.ResponseWriter,
896896
reader = io.NopCloser(io.TeeReader(reader, origBody))
897897
}
898898
err := jsonutil.DecodeJSONFromReader(reader, out)
899-
if err != nil && err != io.EOF {
899+
if err == io.EOF {
900+
// Empty body is not an error.
901+
err = nil
902+
} else if err != nil {
900903
return nil, fmt.Errorf("failed to parse JSON input: %w", err)
901904
}
902905
if origBody != nil {

0 commit comments

Comments
 (0)