From a449b7de54072c42b2647273e12121d2a01c3cec Mon Sep 17 00:00:00 2001 From: Nathan Nichols Date: Wed, 8 Dec 2021 15:51:00 -0800 Subject: [PATCH] Handle case where params is null (#65) * if request does not have parameters, set params to empty [{}] --- src/rpc/RPC.cpp | 2 +- src/webserver/HttpBase.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/RPC.cpp b/src/rpc/RPC.cpp index 8ea88905..006f60fd 100644 --- a/src/rpc/RPC.cpp +++ b/src/rpc/RPC.cpp @@ -37,7 +37,7 @@ make_HttpContext( if (command == "subscribe" || command == "unsubscribe") return {}; - if (!request.contains("params") || !request.at("params").is_array()) + if (!request.at("params").is_array()) return {}; boost::json::array const& array = request.at("params").as_array(); diff --git a/src/webserver/HttpBase.h b/src/webserver/HttpBase.h index 98d68cd2..152b4bc0 100644 --- a/src/webserver/HttpBase.h +++ b/src/webserver/HttpBase.h @@ -111,6 +111,9 @@ handle_request( try { request = boost::json::parse(req.body()).as_object(); + + if (!request.contains("params")) + request["params"] = boost::json::array({ boost::json::object {} }); } catch (std::runtime_error const& e) {