1 #pragma once 2 3 #include <app.hpp> 4 #include <http_request.hpp> 5 #include <http_response.hpp> 6 7 #include <string> 8 9 namespace redfish 10 { 11 12 inline void redfishGet(App& app, const crow::Request& req, 13 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 14 { 15 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 16 { 17 return; 18 } 19 asyncResp->res.jsonValue["v1"] = "/redfish/v1/"; 20 } 21 22 inline void redfish404(App& app, const crow::Request& req, 23 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24 const std::string& path) 25 { 26 asyncResp->res.addHeader(boost::beast::http::field::allow, ""); 27 28 // If we fall to this route, we didn't have a more specific route, so return 29 // 404 30 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 31 { 32 return; 33 } 34 35 BMCWEB_LOG_ERROR << "404 on path " << path; 36 37 boost::urls::string_value name = req.urlView.segments().back(); 38 std::string_view nameStr(name.data(), name.size()); 39 // Note, if we hit the wildcard route, we don't know the "type" the user was 40 // actually requesting, but giving them a return with an empty string is 41 // still better than nothing. 42 messages::resourceNotFound(asyncResp->res, "", nameStr); 43 } 44 45 inline void requestRoutesRedfish(App& app) 46 { 47 BMCWEB_ROUTE(app, "/redfish/") 48 .methods(boost::beast::http::verb::get)( 49 std::bind_front(redfishGet, std::ref(app))); 50 51 BMCWEB_ROUTE(app, "/redfish/<path>") 52 (std::bind_front(redfish404, std::ref(app))); 53 } 54 55 } // namespace redfish 56