virthttp  0.0
libvirt http interface
beast_internals.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <iostream>
3 #include <boost/beast/core/error.hpp>
4 
5 // Report a failure
6 void fail(boost::beast::error_code ec, const char* what) { std::cerr << what << ": " << ec.message() << "\n"; }
7 
8 // Return a reasonable mime type based on the extension of a file.
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);
16  }();
17  if (iequals(ext, ".htm"))
18  return "text/html";
19  if (iequals(ext, ".html"))
20  return "text/html";
21  if (iequals(ext, ".php"))
22  return "text/html";
23  if (iequals(ext, ".css"))
24  return "text/css";
25  if (iequals(ext, ".txt"))
26  return "text/plain";
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"))
36  return "video/x-flv";
37  if (iequals(ext, ".png"))
38  return "image/png";
39  if (iequals(ext, ".jpe"))
40  return "image/jpeg";
41  if (iequals(ext, ".jpeg"))
42  return "image/jpeg";
43  if (iequals(ext, ".jpg"))
44  return "image/jpeg";
45  if (iequals(ext, ".gif"))
46  return "image/gif";
47  if (iequals(ext, ".bmp"))
48  return "image/bmp";
49  if (iequals(ext, ".ico"))
50  return "image/vnd.microsoft.icon";
51  if (iequals(ext, ".tiff"))
52  return "image/tiff";
53  if (iequals(ext, ".tif"))
54  return "image/tiff";
55  if (iequals(ext, ".svg"))
56  return "image/svg+xml";
57  if (iequals(ext, ".svgz"))
58  return "image/svg+xml";
59  return "application/text";
60 }
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