From 6c1cc0b2c854dd56dcb6238816a6ce2cb493c71c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 10 May 2020 18:18:37 +0200 Subject: Separated out lib --- libcommon/mime.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 libcommon/mime.cpp (limited to 'libcommon/mime.cpp') diff --git a/libcommon/mime.cpp b/libcommon/mime.cpp new file mode 100644 index 0000000..f093596 --- /dev/null +++ b/libcommon/mime.cpp @@ -0,0 +1,41 @@ +#include "mime.h" + +#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) +{ + using beast::iequals; + auto const ext = [&path] + { + auto const pos = path.rfind("."); + if (pos == std::string::npos) + return std::string{}; + return path.substr(pos); + }(); + if(iequals(ext, ".htm")) return "text/html"; + if(iequals(ext, ".html")) return "text/html"; + if(iequals(ext, ".php")) return "text/html"; + if(iequals(ext, ".css")) return "text/css"; + if(iequals(ext, ".txt")) return "text/plain"; + if(iequals(ext, ".js")) return "application/javascript"; + if(iequals(ext, ".json")) return "application/json"; + if(iequals(ext, ".xml")) return "application/xml"; + if(iequals(ext, ".swf")) return "application/x-shockwave-flash"; + if(iequals(ext, ".flv")) return "video/x-flv"; + if(iequals(ext, ".png")) return "image/png"; + if(iequals(ext, ".jpe")) return "image/jpeg"; + if(iequals(ext, ".jpeg")) return "image/jpeg"; + if(iequals(ext, ".jpg")) return "image/jpeg"; + if(iequals(ext, ".gif")) return "image/gif"; + if(iequals(ext, ".bmp")) return "image/bmp"; + if(iequals(ext, ".ico")) return "image/vnd.microsoft.icon"; + if(iequals(ext, ".tiff")) return "image/tiff"; + if(iequals(ext, ".tif")) return "image/tiff"; + if(iequals(ext, ".svg")) return "image/svg+xml"; + if(iequals(ext, ".svgz")) return "image/svg+xml"; + return "application/text"; +} + -- cgit v1.2.3