| 1146 | } |
| 1147 | |
| 1148 | HTTPRequestHandlerFactoryPtr createPredefinedHandlerFactory(IServer & server, const std::string & config_prefix) |
| 1149 | { |
| 1150 | Poco::Util::AbstractConfiguration & configuration = server.config(); |
| 1151 | |
| 1152 | if (!configuration.has(config_prefix + ".handler.query")) |
| 1153 | throw Exception("There is no path '" + config_prefix + ".handler.query' in configuration file.", ErrorCodes::NO_ELEMENTS_IN_CONFIG); |
| 1154 | |
| 1155 | std::string predefined_query = configuration.getString(config_prefix + ".handler.query"); |
| 1156 | NameSet analyze_receive_params = analyzeReceiveQueryParams(predefined_query); |
| 1157 | |
| 1158 | std::unordered_map<String, CompiledRegexPtr> headers_name_with_regex; |
| 1159 | Poco::Util::AbstractConfiguration::Keys headers_name; |
| 1160 | configuration.keys(config_prefix + ".headers", headers_name); |
| 1161 | |
| 1162 | for (const auto & header_name : headers_name) |
| 1163 | { |
| 1164 | auto expression = configuration.getString(config_prefix + ".headers." + header_name); |
| 1165 | |
| 1166 | if (!startsWith(expression, "regex:")) |
| 1167 | continue; |
| 1168 | |
| 1169 | expression = expression.substr(6); |
| 1170 | auto regex = getCompiledRegex(expression); |
| 1171 | if (capturingNamedQueryParam(analyze_receive_params, regex)) |
| 1172 | headers_name_with_regex.emplace(std::make_pair(header_name, regex)); |
| 1173 | } |
| 1174 | |
| 1175 | std::shared_ptr<HandlingRuleHTTPHandlerFactory<PredefinedQueryHandler>> factory; |
| 1176 | |
| 1177 | if (configuration.has(config_prefix + ".url")) |
| 1178 | { |
| 1179 | auto url_expression = configuration.getString(config_prefix + ".url"); |
| 1180 | |
| 1181 | if (startsWith(url_expression, "regex:")) |
| 1182 | url_expression = url_expression.substr(6); |
| 1183 | |
| 1184 | auto regex = getCompiledRegex(url_expression); |
| 1185 | if (capturingNamedQueryParam(analyze_receive_params, regex)) |
| 1186 | { |
| 1187 | factory = std::make_shared<HandlingRuleHTTPHandlerFactory<PredefinedQueryHandler>>( |
| 1188 | server, |
| 1189 | std::move(analyze_receive_params), |
| 1190 | std::move(predefined_query), |
| 1191 | std::move(regex), |
| 1192 | std::move(headers_name_with_regex)); |
| 1193 | factory->addFiltersFromConfig(configuration, config_prefix); |
| 1194 | return factory; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | factory = std::make_shared<HandlingRuleHTTPHandlerFactory<PredefinedQueryHandler>>( |
| 1199 | server, std::move(analyze_receive_params), std::move(predefined_query), CompiledRegexPtr{}, std::move(headers_name_with_regex)); |
| 1200 | factory->addFiltersFromConfig(configuration, config_prefix); |
| 1201 | |
| 1202 | return factory; |
| 1203 | } |
| 1204 | |
| 1205 | } |
no test coverage detected