diff options
author | James Feist <james.feist@linux.intel.com> | 2020-03-13 02:32:08 +0300 |
---|---|---|
committer | James Feist <james.feist@linux.intel.com> | 2020-03-17 19:33:52 +0300 |
commit | fe30672809d9dcf83f6cab821d02650b250664b9 (patch) | |
tree | fafba78ccfd37847fe927057c30213979bbff46e /redfish-core/lib/task.hpp | |
parent | f857e9ae6f6e7d567462f32cb5d9d3a7b581535e (diff) | |
download | bmcweb-fe30672809d9dcf83f6cab821d02650b250664b9.tar.xz |
Task: Add payload support
This adds the payload values to task responses.
Tested: passed validator
Change-Id: I50467e28ce8142d198f916ea0c63bd413edcd524
Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'redfish-core/lib/task.hpp')
-rw-r--r-- | redfish-core/lib/task.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index e95eb2e4b7..e224d6cd5a 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -32,6 +32,58 @@ static std::deque<std::shared_ptr<struct TaskData>> tasks; constexpr bool completed = true; +struct Payload +{ + Payload(const crow::Request &req) : + targetUri(req.url), httpOperation(req.methodString()), + httpHeaders(nlohmann::json::array()) + + { + using field_ns = boost::beast::http::field; + constexpr const std::array<boost::beast::http::field, 7> + headerWhitelist = {field_ns::accept, field_ns::accept_encoding, + field_ns::user_agent, field_ns::host, + field_ns::connection, field_ns::content_length, + field_ns::upgrade}; + + jsonBody = nlohmann::json::parse(req.body, nullptr, false); + if (jsonBody.is_discarded()) + { + jsonBody = nullptr; + } + + for (const auto &field : req.fields) + { + if (std::find(headerWhitelist.begin(), headerWhitelist.end(), + field.name()) == headerWhitelist.end()) + { + continue; + } + std::string header; + header.reserve(field.name_string().size() + 2 + + field.value().size()); + header += field.name_string(); + header += ": "; + header += field.value(); + httpHeaders.emplace_back(std::move(header)); + } + } + Payload() = delete; + + std::string targetUri; + std::string httpOperation; + nlohmann::json httpHeaders; + nlohmann::json jsonBody; +}; + +inline void to_json(nlohmann::json &j, const Payload &p) +{ + j = {{"TargetUri", p.targetUri}, + {"HttpOperation", p.httpOperation}, + {"HttpHeaders", p.httpHeaders}, + {"JsonBody", p.jsonBody.dump()}}; +} + struct TaskData : std::enable_shared_from_this<TaskData> { private: @@ -169,6 +221,7 @@ struct TaskData : std::enable_shared_from_this<TaskData> boost::asio::steady_timer timer; std::unique_ptr<sdbusplus::bus::match::match> match; std::optional<time_t> endTime; + std::optional<Payload> payload; bool gave204 = false; }; @@ -299,6 +352,10 @@ class Task : public Node asyncResp->res.jsonValue["TaskMonitor"] = "/redfish/v1/TaskService/Tasks/" + strParam + "/Monitor"; } + if (ptr->payload) + { + asyncResp->res.jsonValue["Payload"] = *(ptr->payload); + } } }; |