summaryrefslogtreecommitdiff
path: root/http/utility.hpp
diff options
context:
space:
mode:
authorCarson Labrado <clabrado@google.com>2022-05-18 03:12:52 +0300
committerEd Tanous <edtanous@google.com>2022-08-24 00:47:32 +0300
commit1c0bb5c6f90b772150accb1f590227589e2179ff (patch)
tree8c3a66c0ea158098f5a2dcd178e1bf297977e429 /http/utility.hpp
parent46a81465f991637341b0a877b3a027db58a3d330 (diff)
downloadbmcweb-1c0bb5c6f90b772150accb1f590227589e2179ff.tar.xz
Redfish Aggregation: Fixup aggregated URIs
URIs in the responses returned with Redfish Aggregation enabled will potentially be incorrect since ones from satellite BMCs will not include the associated prefix such as "5B247A_" in the resource ID portion of the URIs. This patch fixes those links so that they include their BMC's associated prefix. Note that a future patch will be needed to add prefixes to aggregated resources that would appear under collection URIs such as "/redfish/v1/Chassis". Tested: Requests were sent to URIs associated with the aggregating BMC and a satellite BMC denoted as "5B247A". The URIs in the responses were successfully updated such that "5B247A_" was added for satellite resources. Signed-off-by: Carson Labrado <clabrado@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4f976fab1ca1e8603f7cf55292732ffb71cd03e
Diffstat (limited to 'http/utility.hpp')
-rw-r--r--http/utility.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/http/utility.hpp b/http/utility.hpp
index 2ba9b0ea08..d4b9b67421 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -672,6 +672,36 @@ inline bool readUrlSegments(const boost::urls::url_view& urlView,
return details::readUrlSegments(urlView, {std::forward<Args>(args)...});
}
+inline boost::urls::url replaceUrlSegment(const boost::urls::url_view& urlView,
+ const uint replaceLoc,
+ const std::string_view newSegment)
+{
+ const boost::urls::segments_view& urlSegments = urlView.segments();
+ boost::urls::url url("/");
+
+ if (!urlSegments.is_absolute())
+ {
+ return url;
+ }
+
+ boost::urls::segments_view::iterator it = urlSegments.begin();
+ boost::urls::segments_view::iterator end = urlSegments.end();
+
+ for (uint idx = 0; it != end; it++, idx++)
+ {
+ if (idx == replaceLoc)
+ {
+ url.segments().push_back(newSegment);
+ }
+ else
+ {
+ url.segments().push_back(*it);
+ }
+ }
+
+ return url;
+}
+
inline std::string setProtocolDefaults(const boost::urls::url_view& url)
{
if (url.scheme() == "https")