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