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

Method writeResponse

src/Server/StaticRequestHandler.cpp:134–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void 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
167StaticRequestHandler::StaticRequestHandler(IServer & server_, const String & expression, int status_, const String & content_type_)
168 : server(server_), status(status_), content_type(content_type_), response_expression(expression)

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected