From 8672b45b3d4addab9ff0dccb90e6772739038b5f Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 10 Sep 2020 16:07:37 +0100 Subject: [PATCH] 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 --- rpc.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rpc.go b/rpc.go index e382391..17c4b37 100644 --- a/rpc.go +++ b/rpc.go @@ -364,6 +364,13 @@ func requestPayload(r *http.Request) ([]byte, error) { bodybuf = b } 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 { return out, nil } @@ -410,7 +417,6 @@ func requestPayload(r *http.Request) ([]byte, error) { //fallback to previous unknown behaviour return bodybuf, nil - } return []byte{}, nil