blob: cbd13b42f43c9f43788bda6b1070c313c25f33aa [file] [log] [blame]
Ed Tanous911ac312017-08-15 09:37:42 -07001#pragma once
2
Ed Tanous04e438c2020-10-03 08:06:26 -07003#include <app.hpp>
Ed Tanousa8c4ce92021-03-24 08:44:51 -07004#include <http_request.hpp>
5#include <http_response.hpp>
Ed Tanousa8c4ce92021-03-24 08:44:51 -07006
7#include <string>
Ed Tanous1abe55e2018-09-05 08:30:59 -07008
Ed Tanous1abe55e2018-09-05 08:30:59 -07009namespace redfish
10{
Ed Tanousa8c4ce92021-03-24 08:44:51 -070011
Ed Tanousd3355c52022-05-11 14:40:49 -070012inline void redfishGet(App& app, const crow::Request& req,
13 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14{
Carson Labrado3ba00072022-06-06 19:40:56 +000015 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanousd3355c52022-05-11 14:40:49 -070016 {
17 return;
18 }
19 asyncResp->res.jsonValue["v1"] = "/redfish/v1/";
20}
21
Ed Tanous8c623a92022-05-24 11:54:51 -070022inline 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 Tanousf65fca62022-05-24 12:49:41 -070045inline void requestRoutesRedfish(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070046{
47 BMCWEB_ROUTE(app, "/redfish/")
Ed Tanousb41187f2019-10-24 16:30:02 -070048 .methods(boost::beast::http::verb::get)(
Ed Tanousd3355c52022-05-11 14:40:49 -070049 std::bind_front(redfishGet, std::ref(app)));
Ed Tanous8c623a92022-05-24 11:54:51 -070050
51 BMCWEB_ROUTE(app, "/redfish/<path>")
52 (std::bind_front(redfish404, std::ref(app)));
Ed Tanous3dac7492017-08-02 13:46:20 -070053}
Ed Tanousf65fca62022-05-24 12:49:41 -070054
Ed Tanous1abe55e2018-09-05 08:30:59 -070055} // namespace redfish