Mercurial > hg > orthanc
diff Core/SystemToolbox.cpp @ 2906:2a504fef4ed7
AutodetectMimeType() now using boost::filesystem
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Oct 2018 12:29:55 +0100 |
parents | f790999a250a |
children | 9d277f8ad698 |
line wrap: on
line diff
--- a/Core/SystemToolbox.cpp Tue Oct 30 11:55:23 2018 +0100 +++ b/Core/SystemToolbox.cpp Tue Oct 30 12:29:55 2018 +0100 @@ -578,4 +578,71 @@ return threads; } } + + + std::string SystemToolbox::AutodetectMimeType(const std::string& path) + { + std::string extension = boost::filesystem::extension(path); + Toolbox::ToLowerCase(extension); + + // http://en.wikipedia.org/wiki/Mime_types + // Text types + if (extension == ".txt") + { + return MIME_PLAIN_TEXT; + } + else if (extension == ".html") + { + return "text/html"; + } + else if (extension == ".xml") + { + return MIME_XML; + } + else if (extension == ".css") + { + return "text/css"; + } + + // Application types + else if (extension == ".js") + { + return "application/javascript"; + } + else if (extension == ".json") + { + return MIME_JSON; + } + else if (extension == ".pdf") + { + return MIME_PDF; + } + else if (extension == ".wasm") + { + return "application/wasm"; + } + + // Images types + else if (extension == ".jpg" || + extension == ".jpeg") + { + return MIME_JPEG; + } + else if (extension == ".gif") + { + return "image/gif"; + } + else if (extension == ".png") + { + return MIME_PNG; + } + else if (extension == ".pam") + { + return MIME_PAM; + } + else + { + return ""; + } + } }