MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / handle_file_request

Method handle_file_request

dependencies/httplib/httplib.h:5267–5295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5265}
5266
5267inline bool Server::handle_file_request(const Request &req, Response &res,
5268 bool head) {
5269 for (const auto &entry : base_dirs_) {
5270 // Prefix match
5271 if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) {
5272 std::string sub_path = "/" + req.path.substr(entry.mount_point.size());
5273 if (detail::is_valid_path(sub_path)) {
5274 auto path = entry.base_dir + sub_path;
5275 if (path.back() == '/') { path += "index.html"; }
5276
5277 if (detail::is_file(path)) {
5278 detail::read_file(path, res.body);
5279 auto type =
5280 detail::find_content_type(path, file_extension_and_mimetype_map_);
5281 if (type) { res.set_header("Content-Type", type); }
5282 for (const auto &kv : entry.headers) {
5283 res.set_header(kv.first.c_str(), kv.second);
5284 }
5285 res.status = req.has_header("Range") ? 206 : 200;
5286 if (!head && file_request_handler_) {
5287 file_request_handler_(req, res);
5288 }
5289 return true;
5290 }
5291 }
5292 }
5293 }
5294 return false;
5295}
5296
5297inline socket_t
5298Server::create_server_socket(const char *host, int port, int socket_flags,

Callers

nothing calls this directly

Calls 7

is_valid_pathFunction · 0.85
is_fileFunction · 0.85
read_fileFunction · 0.85
find_content_typeFunction · 0.85
set_headerMethod · 0.80
has_headerMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected