api/handler/rpc: fix encoding of inner message (#1601)

* api/handler/rpc: fix encoding of inner message

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-05-04 15:50:53 +03:00 committed by GitHub
parent 38cdb9cc2f
commit 90dd1f63c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -397,13 +397,29 @@ func requestPayload(r *http.Request) ([]byte, error) {
return out, nil return out, nil
} }
} }
var jsonbody map[string]interface{}
if json.Valid(bodybuf) {
if err = json.Unmarshal(bodybuf, &jsonbody); err != nil {
return nil, err
}
}
dstmap := make(map[string]interface{}) dstmap := make(map[string]interface{})
ps := strings.Split(bodydst, ".") ps := strings.Split(bodydst, ".")
if len(ps) == 1 { if len(ps) == 1 {
dstmap[ps[0]] = bodybuf if jsonbody != nil {
dstmap[ps[0]] = jsonbody
} else {
// old unexpected behaviour
dstmap[ps[0]] = bodybuf
}
} else { } else {
em := make(map[string]interface{}) em := make(map[string]interface{})
em[ps[len(ps)-1]] = bodybuf if jsonbody != nil {
em[ps[len(ps)-1]] = jsonbody
} else {
// old unexpected behaviour
em[ps[len(ps)-1]] = bodybuf
}
for i := len(ps) - 2; i > 0; i-- { for i := len(ps) - 2; i > 0; i-- {
nm := make(map[string]interface{}) nm := make(map[string]interface{})
nm[ps[i]] = em nm[ps[i]] = em