aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-01 20:55:22 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-01 20:55:22 +0200
commit20558ecd2b0b9e0d5a7878e4eaba8cc2dfde2f1b (patch)
tree587f50ad83a332892270da98ba5ddf098c54be2a
parentf6225ac6cc21b397a2b302f4e76fcc8499927833 (diff)
downloadjson-rpc-shell-20558ecd2b0b9e0d5a7878e4eaba8cc2dfde2f1b.tar.gz
json-rpc-shell-20558ecd2b0b9e0d5a7878e4eaba8cc2dfde2f1b.tar.xz
json-rpc-shell-20558ecd2b0b9e0d5a7878e4eaba8cc2dfde2f1b.zip
json-rpc-test-server: make sure to set the id in responses
-rw-r--r--json-rpc-test-server.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/json-rpc-test-server.c b/json-rpc-test-server.c
index 6bb1e07..8c51ac4 100644
--- a/json-rpc-test-server.c
+++ b/json-rpc-test-server.c
@@ -1428,6 +1428,8 @@ end:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/// Handlers must not set the `id` field in their responses, that will be filled
+/// in automatically according to whether the request is a notification or not.
typedef json_t *(*json_rpc_handler_fn) (struct server_context *, json_t *);
struct json_rpc_handler_info
@@ -1493,7 +1495,10 @@ process_json_rpc_request (struct server_context *ctx, json_t *request)
json_t *response = handler->handler (ctx, params);
if (id)
+ {
+ (void) json_object_set (response, "id", id);
return response;
+ }
// Notifications don't get responses
json_decref (response);