diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-10 18:18:37 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-10 18:18:37 +0200 |
commit | 6c1cc0b2c854dd56dcb6238816a6ce2cb493c71c (patch) | |
tree | de041dfb3bc12a04fa4defdbd286d098f34adddc /plugins/cgi/cgi.cpp | |
parent | 5b32a4415c9776dd6cae859c8d718b5e68f01d81 (diff) |
Separated out lib
Diffstat (limited to 'plugins/cgi/cgi.cpp')
-rw-r--r-- | plugins/cgi/cgi.cpp | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/plugins/cgi/cgi.cpp b/plugins/cgi/cgi.cpp index 0824d67..480ae9e 100644 --- a/plugins/cgi/cgi.cpp +++ b/plugins/cgi/cgi.cpp @@ -1,5 +1,7 @@ #include "cgi.h" +#include "libcommon/mime.h" + #include <boost/algorithm/string/predicate.hpp> #include <boost/coroutine2/coroutine.hpp> #include <boost/process.hpp> @@ -45,41 +47,6 @@ namespace { } }; - // Return a reasonable mime type based on the extension of a file. - std::string mime_type(fs::path path) - { - using boost::algorithm::iequals; - auto const ext = [&path] - { - size_t pos = path.string().rfind("."); - if (pos == std::string::npos) - return std::string{}; - return path.string().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"; - } - typedef boost::coroutines2::coroutine<std::string> coro_t; // returns true iff std::string is empty or contains newline @@ -306,7 +273,7 @@ std::string cgi_plugin::generate_page( return HttpStatus("500", "Bad file status access: "s + rel_target, SetResponseHeader); } - SetResponseHeader("content_type", mime_type(path)); + SetResponseHeader("content_type", mime_type(path.string())); CGIContext context(GetServerParam, GetRequestParam, SetResponseHeader, path, file_path, path_info); |