Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 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 | |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame^] | 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 | |
Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 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 { |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame^] | 38 | processAllParams(app, query, handler, res); |
Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 39 | }); |
| 40 | return true; |
| 41 | } |
| 42 | } // namespace redfish |