blob: 44f07ba04882060dc3f45b60b1e4f0d0a6e97d25 [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
26 std::function<void(crow::Response&)> handler =
27 res.releaseCompleteRequestHandler();
28
29 res.setCompleteRequestHandler(
30 [&app, handler(std::move(handler)),
31 query{*queryOpt}](crow::Response& res) mutable {
32 processAllParams(app, query, res, handler);
33 });
34 return true;
35}
36} // namespace redfish