summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--debian/changelog6
-rw-r--r--libcommon/mime.cpp44
2 files changed, 28 insertions, 22 deletions
diff --git a/debian/changelog b/debian/changelog
index ba76792..3733e17 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+webserver (1.15~beta1) unstable; urgency=medium
+
+ * Improve MIME handling
+
+ -- Roland Reichwein <mail@reichwein.it> Sat, 09 Oct 2021 16:08:52 +0200
+
webserver (1.14) unstable; urgency=medium
* Bugfix: URL decoding in static files plugin
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";
}