MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / writeResponse

Method writeResponse

src/Server/StaticRequestHandler.cpp:113–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void StaticRequestHandler::writeResponse(WriteBuffer & out)
114{
115 static const String file_prefix = "file://";
116 static const String config_prefix = "config://";
117
118 if (startsWith(response_expression, file_prefix))
119 {
120 auto file_name = response_expression.substr(file_prefix.size(), response_expression.size() - file_prefix.size());
121 if (file_name.starts_with('/'))
122 file_name = file_name.substr(1);
123
124 fs::path user_files_absolute_path = fs::canonical(fs::path(server.context()->getUserFilesPath()));
125 String file_path = fs::weakly_canonical(user_files_absolute_path / file_name);
126
127 if (!fs::exists(file_path))
128 throw Exception(ErrorCodes::INCORRECT_FILE_NAME, "Invalid file name {} for static HTTPHandler. ", file_path);
129
130 ReadBufferFromFile in(file_path);
131 copyData(in, out);
132 }
133 else if (startsWith(response_expression, config_prefix))
134 {
135 if (response_expression.size() <= config_prefix.size())
136 throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER,
137 "Static handling rule handler must contain a complete configuration path, for example: "
138 "config://config_key");
139
140 const auto & config_path = response_expression.substr(config_prefix.size(), response_expression.size() - config_prefix.size());
141 writeString(server.config().getRawString(config_path, "Ok.\n"), out);
142 }
143 else
144 writeString(response_expression, out);
145}
146
147StaticRequestHandler::StaticRequestHandler(
148 IServer & server_, const String & expression, const std::unordered_map<String, String> & http_response_headers_override_, int status_)

Callers

nothing calls this directly

Calls 10

copyDataFunction · 0.85
getUserFilesPathMethod · 0.80
startsWithFunction · 0.50
existsFunction · 0.50
ExceptionClass · 0.50
writeStringFunction · 0.50
sizeMethod · 0.45
contextMethod · 0.45
getRawStringMethod · 0.45
configMethod · 0.45

Tested by

no test coverage detected