#include "mime.h" #include #include namespace beast = boost::beast; // Return a reasonable mime type based on the extension of a file. std::string mime_type(const std::string& path) { auto const ext = [&path] { auto const pos = path.rfind("."); if (pos == std::string::npos) return std::string{}; return path.substr(pos); }(); if(boost::algorithm::istarts_with(ext, ".htm")) return "text/html"; if(boost::algorithm::istarts_with(ext, ".html")) return "text/html"; if(boost::algorithm::istarts_with(ext, ".php")) return "text/html"; if(boost::algorithm::istarts_with(ext, ".css")) return "text/css"; if(boost::algorithm::istarts_with(ext, ".txt")) return "text/plain"; if(boost::algorithm::istarts_with(ext, ".js")) return "application/javascript"; if(boost::algorithm::istarts_with(ext, ".json")) return "application/json"; if(boost::algorithm::istarts_with(ext, ".xml")) return "application/xml"; if(boost::algorithm::istarts_with(ext, ".swf")) return "application/x-shockwave-flash"; if(boost::algorithm::istarts_with(ext, ".flv")) return "video/x-flv"; if(boost::algorithm::istarts_with(ext, ".png")) return "image/png"; if(boost::algorithm::istarts_with(ext, ".jpe")) return "image/jpeg"; if(boost::algorithm::istarts_with(ext, ".jpeg")) return "image/jpeg"; if(boost::algorithm::istarts_with(ext, ".jpg")) return "image/jpeg"; if(boost::algorithm::istarts_with(ext, ".gif")) return "image/gif"; if(boost::algorithm::istarts_with(ext, ".bmp")) return "image/bmp"; if(boost::algorithm::istarts_with(ext, ".ico")) return "image/vnd.microsoft.icon"; if(boost::algorithm::istarts_with(ext, ".tiff")) return "image/tiff"; if(boost::algorithm::istarts_with(ext, ".tif")) return "image/tiff"; if(boost::algorithm::istarts_with(ext, ".svg")) return "image/svg+xml"; if(boost::algorithm::istarts_with(ext, ".svgz")) return "image/svg+xml"; return "application/text"; }