mjson icon indicating copy to clipboard operation
mjson copied to clipboard

JSONRPC request with no 'method' but with 'id'

Open clcconan opened this issue 2 years ago • 2 comments

A request like this, {"jsonrpc": "2.0", "params": [42, 23], "id": 1}. Should we send back a error response with id?

clcconan avatar Apr 28 '23 02:04 clcconan

If I understand the JSON-RPC 2.0 specification correctly, when a request is missing the mandatory method field, the response should indicate an invalid request error as shown below.

Request:

{"jsonrpc": "2.0", "params": [42, 23], "id": 1}

Response:

{"jsonrpc": "2.0", "id": 1, "error": {"code": -32600, "message": "Invalid Request"}}

I have some changes in a fork of this repo which relate to error messages in the mjson jsronrpc handler. I will consider making a pull request.

nicreuss avatar Apr 28 '23 12:04 nicreuss

I have the same understand with you. As you show, if a request has the correct 'id' item, the response will also has a correct 'id' item, no matter if the request has a 'method' item. But if I use the mjson correctly, now the response will not response with the correct request 'id' item. Request:

{"jsonrpc": "2.0", "params": [42, 23], "id": 1} now Response:

{"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null} or {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}}

expect Response: {"jsonrpc": "2.0", "id": 1, "error": {"code": -32600, "message": "Invalid Request"}}

Sorry, The new commit 'https://github.com/cesanta/mjson/pull/61' seems fixed this issues, thanks a lot.

clcconan avatar May 04 '23 01:05 clcconan