| 1015 | } |
| 1016 | |
| 1017 | HTTPRequestHandlerFactoryPtr createPredefinedHandlerFactory(IServer & server, |
| 1018 | const Poco::Util::AbstractConfiguration & config, |
| 1019 | const std::string & config_prefix, |
| 1020 | std::unordered_map<String, String> & common_headers) |
| 1021 | { |
| 1022 | if (!config.has(config_prefix + ".handler.query")) |
| 1023 | throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no path '{}.handler.query' in configuration file.", config_prefix); |
| 1024 | |
| 1025 | std::string predefined_query = config.getString(config_prefix + ".handler.query"); |
| 1026 | /// Remove leading and trailing whitespace that may come from XML formatting in the config file. |
| 1027 | /// This prevents whitespace from being interpreted as data for binary formats like MsgPack. |
| 1028 | boost::algorithm::trim(predefined_query); |
| 1029 | NameSet analyze_receive_params = analyzeReceiveQueryParams(predefined_query); |
| 1030 | |
| 1031 | HTTPHandlerConnectionConfig connection_config(config, config_prefix); |
| 1032 | |
| 1033 | /// Regular expressions from the rule's url/headers whose named capturing groups are referenced by the query; |
| 1034 | /// their captured values are passed to the query as parameters by PredefinedQueryHandler::customizeContext. |
| 1035 | auto regexps = HTTPHandlerRegexpsWithNamedGroups::fromConfig(config, config_prefix, analyze_receive_params); |
| 1036 | |
| 1037 | HTTPResponseHeaderSetup http_response_headers_override = parseHTTPResponseHeaders(config, config_prefix); |
| 1038 | if (!common_headers.empty()) |
| 1039 | { |
| 1040 | if (!http_response_headers_override.has_value()) |
| 1041 | http_response_headers_override.emplace(); |
| 1042 | http_response_headers_override.value().insert(common_headers.begin(), common_headers.end()); |
| 1043 | } |
| 1044 | |
| 1045 | auto creator = [ |
| 1046 | &server, |
| 1047 | analyze_receive_params, |
| 1048 | predefined_query, |
| 1049 | url_regexp = regexps.url_regexp, |
| 1050 | headers_name_with_regexp = std::move(regexps.headers_name_with_regexp), |
| 1051 | http_response_headers_override, |
| 1052 | connection_config] |
| 1053 | -> std::unique_ptr<PredefinedQueryHandler> |
| 1054 | { |
| 1055 | return std::make_unique<PredefinedQueryHandler>( |
| 1056 | server, |
| 1057 | connection_config, |
| 1058 | analyze_receive_params, |
| 1059 | predefined_query, |
| 1060 | url_regexp, |
| 1061 | headers_name_with_regexp, |
| 1062 | http_response_headers_override); |
| 1063 | }; |
| 1064 | auto factory = std::make_shared<HandlingRuleHTTPHandlerFactory<PredefinedQueryHandler>>(std::move(creator)); |
| 1065 | factory->addFiltersFromConfig(config, config_prefix); |
| 1066 | return factory; |
| 1067 | } |
| 1068 | |
| 1069 | void HTTPHandler::Output::pushDelayedResults() const |
| 1070 | { |
no test coverage detected