void send_file(const fs::path& file_path) {
http::response<http::file_body> response{ http::status::ok, request_.version() };
response.set(http::field::server, "Boost.Beast HTTPS Server");
response.set(http::field::access_control_allow_origin, "*");
std::string ext = file_path.extension().string();
if (mime_map.count(ext) > 0) {
response.set(http::field::content_type, mime_map[ext]);
}
else {
response.set(http::field::content_type, "application/octet-stream");
}
response.body().open(file_path.string().c_str(), beast::file_mode::read, ec);
if (ec) {
send_not_found();
return;
}
auto self(shared_from_this());
http::async_write(ssl_stream_, response,
[self](beast::error_code ec, std::size_t bytes_transferred) {
boost::ignore_unused(bytes_transferred);
std::cerr << ec.message() << std::endl;
self->do_close();
});
}