1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "mime.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/beast/http.hpp>
namespace beast = boost::beast;
// Return a reasonable mime type based on the extension of a file.
std::string Reichwein::Mime::mime_type(const std::string& path)
{
auto const pos = path.rfind(".");
if (pos == std::string::npos)
return {};
auto const ext = path.substr(pos);
if(boost::algorithm::iequals(ext, ".htm")) return "text/html";
if(boost::algorithm::iequals(ext, ".html")) return "text/html";
if(boost::algorithm::iequals(ext, ".php")) return "text/html";
if(boost::algorithm::iequals(ext, ".css")) return "text/css";
if(boost::algorithm::iequals(ext, ".txt")) return "text/plain";
if(boost::algorithm::iequals(ext, ".js")) return "application/javascript";
if(boost::algorithm::iequals(ext, ".json")) return "application/json";
if(boost::algorithm::iequals(ext, ".xml")) return "application/xml";
if(boost::algorithm::iequals(ext, ".swf")) return "application/x-shockwave-flash";
if(boost::algorithm::iequals(ext, ".flv")) return "video/x-flv";
if(boost::algorithm::iequals(ext, ".png")) return "image/png";
if(boost::algorithm::iequals(ext, ".jpe")) return "image/jpeg";
if(boost::algorithm::iequals(ext, ".jpeg")) return "image/jpeg";
if(boost::algorithm::iequals(ext, ".jpg")) return "image/jpeg";
if(boost::algorithm::iequals(ext, ".gif")) return "image/gif";
if(boost::algorithm::iequals(ext, ".bmp")) return "image/bmp";
if(boost::algorithm::iequals(ext, ".ico")) return "image/vnd.microsoft.icon";
if(boost::algorithm::iequals(ext, ".tiff")) return "image/tiff";
if(boost::algorithm::iequals(ext, ".tif")) return "image/tiff";
if(boost::algorithm::iequals(ext, ".svg")) return "image/svg+xml";
if(boost::algorithm::iequals(ext, ".svgz")) return "image/svg+xml";
return "application/text";
}
|