From 44e4518b700bd97cdca09d05e3c24712a4799788 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Tue, 26 Jul 2022 16:47:23 -0700 Subject: Allow custom 404 handlers Different HTTP protocols have different http responses for 404. This commit adds support for registering a route designed to host a handler meant for when a response would otherwise return. This allows registering a custom 404 handler for Redfish, for which all routes will now return a Redfish response. This was in response to the 404 handler not working in all cases (in the case of POST/PATCH/DELETE). Allowing an explicit registration helps to give the intended behavior in all cases. Tested: GET /redfish/v1/foo returns 404 Not found PATCH /redfish/v1/foo returns 404 Not found GET /redfish/v1 returns 200 OK, and content PATCH /redfish/v1 returns 405 Method Not Allowed With Redfish Aggregation: GET /redfish/v1/foo gets forwarded to satellite BMC PATCH /redfish/v1/foo does not get forwarded and returns 404 PATCH /redfish/v1/foo/5B247A_bar gets forwarded Unit tests pass Redfish-service-validator passes Redfish-Protocol-Validator fails 7 tests (same as before) Signed-off-by: Ed Tanous Change-Id: I731a5b4e736a2480700d8f3e81f9c9c6cbe6efca Signed-off-by: Carson Labrado --- redfish-core/lib/redfish_v1.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'redfish-core/lib/redfish_v1.hpp') diff --git a/redfish-core/lib/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp index a9a786d7d8..6aa3ee6d5a 100644 --- a/redfish-core/lib/redfish_v1.hpp +++ b/redfish-core/lib/redfish_v1.hpp @@ -137,7 +137,7 @@ inline void requestRoutesRedfish(App& app) // Note, this route must always be registered last BMCWEB_ROUTE(app, "/redfish/") - (std::bind_front(redfish404, std::ref(app))); + .notFound()(std::bind_front(redfish404, std::ref(app))); } } // namespace redfish -- cgit v1.2.3