From 6e686fee894a864aa8a4f6462dd36785dcaeef18 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 11 Dec 2021 14:10:31 +0100 Subject: Improve MIME handling --- debian/changelog | 6 ++++++ libcommon/mime.cpp | 44 ++++++++++++++++++++++---------------------- 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 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 #include 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"; } -- cgit v1.2.3