| 5673 | } |
| 5674 | |
| 5675 | inline 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 | |
| 5705 | inline socket_t |
| 5706 | Server::create_server_socket(const std::string &host, int port, |
nothing calls this directly
no test coverage detected