mirror of
https://github.com/pgsty/minio.git
synced 2026-07-25 06:56:18 +03:00
rpc: Fix json rpc to handle array and object request params.
rpc/v2/json2 code has a bug where it treats all jsonrpc 2.0 request params like an 'object'. In accordance with the spec it could be both 'object' or an 'array'. Handle both cases.
This commit is contained in:
+9
-10
@@ -125,22 +125,21 @@ func (c *CodecRequest) Method() (string, error) {
|
||||
|
||||
// ReadRe<quest fills the request object for the RPC method.
|
||||
func (c *CodecRequest) ReadRequest(args interface{}) error {
|
||||
if c.err == nil {
|
||||
if c.request.Params != nil {
|
||||
// JSON params structured object. Unmarshal to the args object.
|
||||
err := json.Unmarshal(*c.request.Params, args)
|
||||
if err != nil {
|
||||
if c.err == nil && c.request.Params != nil {
|
||||
// Note: if c.request.Params is nil it's not an error, it's an optional member.
|
||||
// JSON params structured object. Unmarshal to the args object.
|
||||
if err := json.Unmarshal(*c.request.Params, args); err != nil {
|
||||
// Structed unmarshalling failed, attempt JSON params as
|
||||
// array value. Unmarshal into array containing the
|
||||
// request struct.
|
||||
params := [1]interface{}{args}
|
||||
if err = json.Unmarshal(*c.request.Params, ¶ms); err != nil {
|
||||
c.err = &Error{
|
||||
Code: E_INVALID_REQ,
|
||||
Message: err.Error(),
|
||||
Data: c.request.Params,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.err = &Error{
|
||||
Code: E_INVALID_REQ,
|
||||
Message: "rpc: method request ill-formed: missing params field",
|
||||
}
|
||||
}
|
||||
}
|
||||
return c.err
|
||||
|
||||
Reference in New Issue
Block a user