1 #pragma once 2 3 #include "utils/query_param.hpp" 4 5 #include <bmcweb_config.h> 6 7 namespace 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 // 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 32 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 { 38 processAllParams(app, query, handler, res); 39 }); 40 return true; 41 } 42 } // namespace redfish 43