1 /** 2 * MIME types for common extensions. 3 * 4 * License: 5 * This Source Code Form is subject to the terms of 6 * the Mozilla Public License, v. 2.0. If a copy of 7 * the MPL was not distributed with this file, You 8 * can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * Authors: 11 * Vladimir Panteleev <vladimir@thecybershadow.net> 12 */ 13 14 module ae.utils.mime; 15 16 import std.string; 17 import std.path; 18 19 string guessMime(string fileName, string defaultResult = null) 20 { 21 string ext = toLower(extension(fileName)); 22 23 if (ext.endsWith("-opt")) 24 ext = ext[0..$-4]; // HACK 25 26 switch (ext) 27 { 28 case ".txt": 29 return "text/plain"; 30 case ".htm": 31 case ".html": 32 return "text/html"; 33 case ".js": 34 return "text/javascript"; 35 case ".css": 36 return "text/css"; 37 case ".png": 38 return "image/png"; 39 case ".gif": 40 return "image/gif"; 41 case ".jpg": 42 case ".jpeg": 43 return "image/jpeg"; 44 case ".svg": 45 return "image/svg+xml"; 46 case ".webm": 47 return "video/webm"; 48 case ".ico": 49 return "image/vnd.microsoft.icon"; 50 51 case ".c": 52 return "text/x-csrc"; 53 case ".h": 54 return "text/x-chdr"; 55 case ".cpp": 56 case ".c++": 57 case ".cxx": 58 case ".cc": 59 return "text/x-c++src"; 60 case ".hpp": 61 case ".h++": 62 case ".hxx": 63 case ".hh": 64 return "text/x-c++hdr"; 65 case ".d": // by extension :P 66 return "text/x-dsrc"; 67 case ".di": 68 return "text/x-dhdr"; 69 70 default: 71 return defaultResult; 72 } 73 }