MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / handle_file_request

Method handle_file_request

examples/server/httplib.h:5675–5703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5673}
5674
5675inline bool Server::handle_file_request(const Request &req, Response &res,
5676 bool head) {
5677 for (const auto &entry : base_dirs_) {
5678 // Prefix match
5679 if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) {
5680 std::string sub_path = "/" + req.path.substr(entry.mount_point.size());
5681 if (detail::is_valid_path(sub_path)) {
5682 auto path = entry.base_dir + sub_path;
5683 if (path.back() == '/') { path += "index.html"; }
5684
5685 if (detail::is_file(path)) {
5686 detail::read_file(path, res.body);
5687 auto type =
5688 detail::find_content_type(path, file_extension_and_mimetype_map_);
5689 if (type) { res.set_header("Content-Type", type); }
5690 for (const auto &kv : entry.headers) {
5691 res.set_header(kv.first.c_str(), kv.second);
5692 }
5693 res.status = req.has_header("Range") ? 206 : 200;
5694 if (!head && file_request_handler_) {
5695 file_request_handler_(req, res);
5696 }
5697 return true;
5698 }
5699 }
5700 }
5701 }
5702 return false;
5703}
5704
5705inline socket_t
5706Server::create_server_socket(const std::string &host, int port,

Callers

nothing calls this directly

Calls 10

is_valid_pathFunction · 0.85
is_fileFunction · 0.85
find_content_typeFunction · 0.85
substrMethod · 0.80
set_headerMethod · 0.80
has_headerMethod · 0.80
read_fileFunction · 0.70
compareMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected