summaryrefslogtreecommitdiffhomepage
path: root/libcommon/mime.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-12-11 14:10:31 +0100
committerRoland Reichwein <mail@reichwein.it>2021-12-11 14:10:31 +0100
commit6e686fee894a864aa8a4f6462dd36785dcaeef18 (patch)
tree5eaf54a3dbfbe4cb3a61864efc0bd0503663a002 /libcommon/mime.cpp
parent9a40db34cd48b776023e3558a855458fa4f9d264 (diff)
Improve MIME handling
Diffstat (limited to 'libcommon/mime.cpp')
-rw-r--r--libcommon/mime.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/libcommon/mime.cpp b/libcommon/mime.cpp
index f093596..f64d046 100644
--- a/libcommon/mime.cpp
+++ b/libcommon/mime.cpp
@@ -1,5 +1,6 @@
#include "mime.h"
+#include <boost/algorithm/string/predicate.hpp>
#include <boost/beast/http.hpp>
namespace beast = boost::beast;
@@ -7,7 +8,6 @@ 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(".");
@@ -15,27 +15,27 @@ std::string mime_type(const std::string& path)
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";
+ 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";
}