| 5265 | } |
| 5266 | |
| 5267 | inline 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 | |
| 5297 | inline socket_t |
| 5298 | Server::create_server_socket(const char *host, int port, int socket_flags, |
nothing calls this directly
no test coverage detected