3 #include <boost/beast/core/error.hpp> 6 void fail(boost::beast::error_code ec,
const char* what) { std::cerr << what <<
": " << ec.message() <<
"\n"; }
9 inline boost::beast::string_view
mime_type(boost::beast::string_view path) {
10 using boost::beast::iequals;
11 auto const ext = [&path] {
12 auto const pos = path.rfind(
".");
13 if (pos == boost::beast::string_view::npos)
14 return boost::beast::string_view{};
15 return path.substr(pos);
17 if (iequals(
ext,
".htm"))
19 if (iequals(
ext,
".html"))
21 if (iequals(
ext,
".php"))
23 if (iequals(
ext,
".css"))
25 if (iequals(
ext,
".txt"))
27 if (iequals(
ext,
".js"))
28 return "application/javascript";
29 if (iequals(
ext,
".json"))
30 return "application/json";
31 if (iequals(
ext,
".xml"))
32 return "application/xml";
33 if (iequals(
ext,
".swf"))
34 return "application/x-shockwave-flash";
35 if (iequals(
ext,
".flv"))
37 if (iequals(
ext,
".png"))
39 if (iequals(
ext,
".jpe"))
41 if (iequals(
ext,
".jpeg"))
43 if (iequals(
ext,
".jpg"))
45 if (iequals(
ext,
".gif"))
47 if (iequals(
ext,
".bmp"))
49 if (iequals(
ext,
".ico"))
50 return "image/vnd.microsoft.icon";
51 if (iequals(
ext,
".tiff"))
53 if (iequals(
ext,
".tif"))
55 if (iequals(
ext,
".svg"))
56 return "image/svg+xml";
57 if (iequals(
ext,
".svgz"))
58 return "image/svg+xml";
59 return "application/text";
boost::beast::string_view mime_type(boost::beast::string_view path)
Definition: beast_internals.hpp:9
void fail(boost::beast::error_code ec, const char *what)
Definition: beast_internals.hpp:6
Definition: utility.hpp:151