api: fix request body re-sequencing bug (#1996)

* api: don't mutate request body on POST requests

* fix test suite

* Improve solution

Co-authored-by: Asim Aslam <asim@aslam.me>
This commit is contained in:
ben-toogood 2020-09-10 16:07:37 +01:00 committed by Vasiliy Tolstov
parent 9c3198e5bd
commit 8672b45b3d

8
rpc.go
View File

@ -364,6 +364,13 @@ func requestPayload(r *http.Request) ([]byte, error) {
bodybuf = b bodybuf = b
} }
if bodydst == "" || bodydst == "*" { if bodydst == "" || bodydst == "*" {
// jsonpatch resequences the json object so we avoid it if possible (some usecases such as
// validating signatures require the request body to be unchangedd). We're keeping support
// for the custom paramaters for backwards compatability reasons.
if string(out) == "{}" {
return bodybuf, nil
}
if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil {
return out, nil return out, nil
} }
@ -410,7 +417,6 @@ func requestPayload(r *http.Request) ([]byte, error) {
//fallback to previous unknown behaviour //fallback to previous unknown behaviour
return bodybuf, nil return bodybuf, nil
} }
return []byte{}, nil return []byte{}, nil