| 132 | } |
| 133 | |
| 134 | void StaticRequestHandler::writeResponse(WriteBuffer & out) |
| 135 | { |
| 136 | static const String file_prefix = "file://"; |
| 137 | static const String config_prefix = "config://"; |
| 138 | |
| 139 | if (startsWith(response_expression, file_prefix)) |
| 140 | { |
| 141 | auto file_name = response_expression.substr(file_prefix.size(), response_expression.size() - file_prefix.size()); |
| 142 | if (file_name.starts_with('/')) |
| 143 | file_name = file_name.substr(1); |
| 144 | |
| 145 | fs::path user_files_absolute_path = fs::canonical(fs::path(server.context()->getUserFilesPath())); |
| 146 | String file_path = fs::weakly_canonical(user_files_absolute_path / file_name); |
| 147 | |
| 148 | if (!fs::exists(file_path)) |
| 149 | throw Exception("Invalid file name " + file_path + " for static HTTPHandler. ", ErrorCodes::INCORRECT_FILE_NAME); |
| 150 | |
| 151 | ReadBufferFromFile in(file_path); |
| 152 | copyData(in, out); |
| 153 | } |
| 154 | else if (startsWith(response_expression, config_prefix)) |
| 155 | { |
| 156 | if (response_expression.size() <= config_prefix.size()) |
| 157 | throw Exception( "Static handling rule handler must contain a complete configuration path, for example: config://config_key", |
| 158 | ErrorCodes::INVALID_CONFIG_PARAMETER); |
| 159 | |
| 160 | const auto & config_path = response_expression.substr(config_prefix.size(), response_expression.size() - config_prefix.size()); |
| 161 | writeString(server.config().getRawString(config_path, "Ok.\n"), out); |
| 162 | } |
| 163 | else |
| 164 | writeString(response_expression, out); |
| 165 | } |
| 166 | |
| 167 | StaticRequestHandler::StaticRequestHandler(IServer & server_, const String & expression, int status_, const String & content_type_) |
| 168 | : server(server_), status(status_), content_type(content_type_), response_expression(expression) |
nothing calls this directly
no test coverage detected