summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorCarson Labrado <clabrado@google.com>2023-03-17 23:27:00 +0300
committerCarson Labrado <clabrado@google.com>2023-03-28 02:16:43 +0300
commitb27e1cbefc2a12a838de209decb7e22b5ba1b2c0 (patch)
treebb4eadf383f4e988c297d90bccec0d487931f77a /redfish-core/include
parent0ed80c8ce93a38eca6951ffad5c3143a3a720053 (diff)
downloadbmcweb-b27e1cbefc2a12a838de209decb7e22b5ba1b2c0.tar.xz
Aggregation: Prefix fix HttpHeaders property
The "HttpHeaders" property in a response is an array of HTTP headers. We perform prefix fixing on the "Location" header from responses so we should also fix any "Location" headers which are contained by "HttpHeaders" in an aggregated response. This requires special handling since each header is represented as a single string in the response. Added testcase for HttpHeaders property Tested: All unit tests pass Signed-off-by: Carson Labrado <clabrado@google.com> Change-Id: I3040c4ea52b2bebcb6e206bb50585c6a75538f0a
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/redfish_aggregator.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 1d340f770b..c640586c10 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -175,6 +175,38 @@ static inline void addAggregatedHeaders(crow::Response& asyncResp,
// TODO: we need special handling for Link Header Value
}
+// Fix HTTP headers which appear in responses from Task resources among others
+static inline void addPrefixToHeadersInResp(nlohmann::json& json,
+ std::string_view prefix)
+{
+ // The passed in "HttpHeaders" should be an array of headers
+ nlohmann::json::array_t* array = json.get_ptr<nlohmann::json::array_t*>();
+ if (array == nullptr)
+ {
+ BMCWEB_LOG_ERROR << "Field wasn't an array_t????";
+ return;
+ }
+
+ for (nlohmann::json& item : *array)
+ {
+ // Each header is a single string with the form "<Field>: <Value>"
+ std::string* strHeader = item.get_ptr<std::string*>();
+ if (strHeader == nullptr)
+ {
+ BMCWEB_LOG_CRITICAL << "Field wasn't a string????";
+ continue;
+ }
+
+ constexpr std::string_view location = "Location: ";
+ if (strHeader->starts_with(location))
+ {
+ std::string header = strHeader->substr(location.size());
+ addPrefixToStringItem(header, prefix);
+ *strHeader = std::string(location) + header;
+ }
+ }
+}
+
// Search the json for all URIs and add the supplied prefix if the URI is for
// an aggregated resource.
static inline void addPrefixes(nlohmann::json& json, std::string_view prefix)
@@ -191,6 +223,14 @@ static inline void addPrefixes(nlohmann::json& json, std::string_view prefix)
continue;
}
+ // "HttpHeaders" contains HTTP headers. Among those we need to
+ // attempt to fix the "Location" header
+ if (item.first == "HttpHeaders")
+ {
+ addPrefixToHeadersInResp(item.second, prefix);
+ continue;
+ }
+
// Recusively parse the rest of the json
addPrefixes(item.second, prefix);
}