summaryrefslogtreecommitdiff
path: root/redfish-core/lib
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2021-09-09 02:40:12 +0300
committerEd Tanous <ed@tanous.net>2021-10-17 23:53:48 +0300
commit601c71aef4ac54e28933bc6e022c7e1f6e8bf1e8 (patch)
tree7935403a56beb6a85749a22e338812c3f0ac9b24 /redfish-core/lib
parent565c0911faea72128a3a8c4b8b5ec3094756d82e (diff)
downloadbmcweb-601c71aef4ac54e28933bc6e022c7e1f6e8bf1e8.tar.xz
Improve HttpHeaders in EventService
This commit moves the internal data structures to use boost::beast::http::fields as its internal data structure. fields is a hyper-optimized map implementation for http headers, and has a lot of nice escaping properties. It is what boost::beast::http::request uses under the covers, so this has some niceties in reducing the amount of code, and means we can completely remove the headers structure, and simply rely on req. When this conversion was done, now the type safety of the incoming data needs to have better checking, as loading into the keys has new requirements (like values must be strings), so that type conversion code for to and from json was added, and the POST and PATCH handler updated to put into the new structure. Tested: curl -vvvv --insecure -u root:0penBmc "https://192.168.7.2:443/redfish/v1/EventService/Subscriptions" -X POST -d "{\"Destination\":\"http://192.168.7.2:443/\",\"Context\":\"Public\",\"Protocol\":\"Redfish\",\"HttpHeaders\":[{\"Foo\":\"Bar\"}]}" returned 200. Tested various "bad" headers, and observed the correct type errors. Issued: systemctl restart bmcweb. Subscription restored properly verified with. GET https://localhost:8001/redfish/v1/EventService/Subscriptions/183211400 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I331f65e1a3960f1812c9baac27dbdcb1d54f112c
Diffstat (limited to 'redfish-core/lib')
-rw-r--r--redfish-core/lib/event_service.hpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 8609862694..b802280b91 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -17,6 +17,7 @@
#include "event_service_manager.hpp"
#include <app.hpp>
+#include <boost/beast/http/fields.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -343,7 +344,22 @@ inline void requestRoutesEventDestinationCollection(App& app)
if (headers)
{
- subValue->httpHeaders = *headers;
+ for (const nlohmann::json& headerChunk : *headers)
+ {
+ for (const auto& item : headerChunk.items())
+ {
+ const std::string* value =
+ item.value().get_ptr<const std::string*>();
+ if (value == nullptr)
+ {
+ messages::propertyValueFormatError(
+ asyncResp->res, item.value().dump(2, true),
+ "HttpHeaders/" + item.key());
+ return;
+ }
+ subValue->httpHeaders.set(item.key(), *value);
+ }
+ }
}
if (regPrefixes)
@@ -577,7 +593,25 @@ inline void requestRoutesEventDestination(App& app)
if (headers)
{
- subValue->httpHeaders = *headers;
+ boost::beast::http::fields fields;
+ for (const nlohmann::json& headerChunk : *headers)
+ {
+ for (auto& it : headerChunk.items())
+ {
+ const std::string* value =
+ it.value().get_ptr<const std::string*>();
+ if (value == nullptr)
+ {
+ messages::propertyValueFormatError(
+ asyncResp->res,
+ it.value().dump(2, ' ', true),
+ "HttpHeaders/" + it.key());
+ return;
+ }
+ fields.set(it.key(), *value);
+ }
+ }
+ subValue->httpHeaders = fields;
}
if (retryPolicy)