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 --- response.cpp | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'response.cpp') diff --git a/response.cpp b/response.cpp index 2320379..4c76bb3 100644 --- a/response.cpp +++ b/response.cpp @@ -5,6 +5,8 @@ #include "file.h" #include "os.h" +#include "libcommon/mime.h" + #include #include @@ -202,42 +204,6 @@ void SetResponseHeader(const std::string& key, const std::string& value, respons throw std::runtime_error("Unsupported response field: "s + key); } -// Return a reasonable mime type based on the extension of a file. -beast::string_view -mime_type(beast::string_view path) -{ - using beast::iequals; - auto const ext = [&path] - { - auto const pos = path.rfind("."); - if (pos == beast::string_view::npos) - return beast::string_view{}; - 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"; -} - response_type HttpStatus(std::string status, std::string message, response_type& res) { if (status != "200") { // already handled at res init -- cgit v1.2.3