blob: b06278b4729422cd6dae11a19da5c4945c3645f8 [file] [log] [blame]
Ed Tanousf4c99e72021-10-04 17:02:43 -07001#pragma once
2
3#include "utils/query_param.hpp"
4
5#include <bmcweb_config.h>
6
7namespace redfish
8{
9
10[[nodiscard]] inline bool setUpRedfishRoute(crow::App& app,
11 const crow::Request& req,
12 crow::Response& res)
13{
14 // If query parameters aren't enabled, do nothing.
15 if constexpr (!bmcwebInsecureEnableQueryParams)
16 {
17 return true;
18 }
19 std::optional<query_param::Query> queryOpt =
20 query_param::parseParameters(req.urlView.params(), res);
21 if (queryOpt == std::nullopt)
22 {
23 return false;
24 }
25
Ed Tanous7cf436c2022-03-22 23:53:51 -070026 // If this isn't a get, no need to do anything with parameters
27 if (req.method() != boost::beast::http::verb::get)
28 {
29 return true;
30 }
31
Ed Tanousf4c99e72021-10-04 17:02:43 -070032 std::function<void(crow::Response&)> handler =
33 res.releaseCompleteRequestHandler();
34
35 res.setCompleteRequestHandler(
36 [&app, handler(std::move(handler)),
37 query{*queryOpt}](crow::Response& res) mutable {
Ed Tanous7cf436c2022-03-22 23:53:51 -070038 processAllParams(app, query, handler, res);
Ed Tanousf4c99e72021-10-04 17:02:43 -070039 });
40 return true;
41}
42} // namespace redfish