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 ".webm": 45 return "video/webm"; 46 case ".ico": 47 return "image/vnd.microsoft.icon"; 48 49 case ".c": 50 return "text/x-csrc"; 51 case ".h": 52 return "text/x-chdr"; 53 case ".cpp": 54 case ".c++": 55 case ".cxx": 56 case ".cc": 57 return "text/x-c++src"; 58 case ".hpp": 59 case ".h++": 60 case ".hxx": 61 case ".hh": 62 return "text/x-c++hdr"; 63 case ".d": // by extension :P 64 return "text/x-dsrc"; 65 case ".di": 66 return "text/x-dhdr"; 67 68 default: 69 return defaultResult; 70 } 71 }