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:
8
rpc.go
8
rpc.go
@@ -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
|
||||||
|
Reference in New Issue
Block a user