Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 3 | #include <app.hpp> |
Ed Tanous | a8c4ce9 | 2021-03-24 08:44:51 -0700 | [diff] [blame] | 4 | #include <http_request.hpp> |
| 5 | #include <http_response.hpp> |
Ed Tanous | a8c4ce9 | 2021-03-24 08:44:51 -0700 | [diff] [blame] | 6 | |
| 7 | #include <string> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 8 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 9 | namespace redfish |
| 10 | { |
Ed Tanous | a8c4ce9 | 2021-03-24 08:44:51 -0700 | [diff] [blame] | 11 | |
Ed Tanous | d3355c5 | 2022-05-11 14:40:49 -0700 | [diff] [blame] | 12 | inline void redfishGet(App& app, const crow::Request& req, |
| 13 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 14 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 15 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | d3355c5 | 2022-05-11 14:40:49 -0700 | [diff] [blame] | 16 | { |
| 17 | return; |
| 18 | } |
| 19 | asyncResp->res.jsonValue["v1"] = "/redfish/v1/"; |
| 20 | } |
| 21 | |
Ed Tanous | 8c623a9 | 2022-05-24 11:54:51 -0700 | [diff] [blame^] | 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 | |
Ed Tanous | f65fca6 | 2022-05-24 12:49:41 -0700 | [diff] [blame] | 45 | inline void requestRoutesRedfish(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 46 | { |
| 47 | BMCWEB_ROUTE(app, "/redfish/") |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 48 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | d3355c5 | 2022-05-11 14:40:49 -0700 | [diff] [blame] | 49 | std::bind_front(redfishGet, std::ref(app))); |
Ed Tanous | 8c623a9 | 2022-05-24 11:54:51 -0700 | [diff] [blame^] | 50 | |
| 51 | BMCWEB_ROUTE(app, "/redfish/<path>") |
| 52 | (std::bind_front(redfish404, std::ref(app))); |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 53 | } |
Ed Tanous | f65fca6 | 2022-05-24 12:49:41 -0700 | [diff] [blame] | 54 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 55 | } // namespace redfish |