mime-types.lisp
  1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: HUNCHENTOOT; Base: 10 -*-
2
3 ;;; Copyright (c) 2004-2010, Dr. Edmund Weitz. All rights reserved.
4
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
7 ;;; are met:
8
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
11
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
16
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 (in-package :hunchentoot)
30
31 (defparameter *mime-type-list* '(("application/andrew-inset" "ez")
32 ("application/cu-seeme" "cu")
33 ("application/dsptype" "tsp")
34 ("application/futuresplash" "spl")
35 ("application/hta" "hta")
36 ("application/java-archive" "jar")
37 ("application/java-serialized-object" "ser")
38 ("application/java-vm" "class")
39 ("application/mac-binhex40" "hqx")
40 ("application/mac-compactpro" "cpt")
41 ("application/mathematica" "nb")
42 ("application/msaccess" "mdb")
43 ("application/msword" "doc" "dot")
44 ("application/octet-stream" "bin")
45 ("application/oda" "oda")
46 ("application/ogg" "ogg")
47 ("application/pdf" "pdf")
48 ("application/pgp-keys" "key")
49 ("application/pgp-signature" "pgp")
50 ("application/pics-rules" "prf")
51 ("application/postscript" "ps" "ai" "eps")
52 ("application/rar" "rar")
53 ("application/rdf+xml" "rdf")
54 ("application/rss+xml" "rss")
55 ("application/smil" "smi" "smil")
56 ("application/wordperfect" "wpd")
57 ("application/wordperfect5.1" "wp5")
58 ("application/xhtml+xml" "xhtml" "xht")
59 ("application/xml" "fo" "xml" "xsl")
60 ("application/zip" "zip")
61 ("application/vnd.cinderella" "cdy")
62 ("application/vnd.mozilla.xul+xml" "xul")
63 ("application/vnd.ms-excel" "xls" "xlb" "xlt")
64 ("application/vnd.ms-pki.seccat" "cat")
65 ("application/vnd.ms-pki.stl" "stl")
66 ("application/vnd.ms-powerpoint" "ppt" "pps")
67 ("application/vnd.oasis.opendocument.chart" "odc")
68 ("application/vnd.oasis.opendocument.database" "odb")
69 ("application/vnd.oasis.opendocument.formula" "odf")
70 ("application/vnd.oasis.opendocument.graphics" "odg")
71 ("application/vnd.oasis.opendocument.graphics-template" "otg")
72 ("application/vnd.oasis.opendocument.image" "odi")
73 ("application/vnd.oasis.opendocument.presentation" "odp")
74 ("application/vnd.oasis.opendocument.presentation-template" "otp")
75 ("application/vnd.oasis.opendocument.spreadsheet" "ods")
76 ("application/vnd.oasis.opendocument.spreadsheet-template" "ots")
77 ("application/vnd.oasis.opendocument.text" "odt")
78 ("application/vnd.oasis.opendocument.text-master" "odm")
79 ("application/vnd.oasis.opendocument.text-template" "ott")
80 ("application/vnd.oasis.opendocument.text-web" "oth")
81 ("application/vnd.rim.cod" "cod")
82 ("application/vnd.smaf" "mmf")
83 ("application/vnd.stardivision.calc" "sdc")
84 ("application/vnd.stardivision.draw" "sda")
85 ("application/vnd.stardivision.impress" "sdd" "sdp")
86 ("application/vnd.stardivision.math" "smf")
87 ("application/vnd.stardivision.writer" "sdw" "vor")
88 ("application/vnd.stardivision.writer-global" "sgl")
89 ("application/vnd.sun.xml.calc" "sxc")
90 ("application/vnd.sun.xml.calc.template" "stc")
91 ("application/vnd.sun.xml.draw" "sxd")
92 ("application/vnd.sun.xml.draw.template" "std")
93 ("application/vnd.sun.xml.impress" "sxi")
94 ("application/vnd.sun.xml.impress.template" "sti")
95 ("application/vnd.sun.xml.math" "sxm")
96 ("application/vnd.sun.xml.writer" "sxw")
97 ("application/vnd.sun.xml.writer.global" "sxg")
98 ("application/vnd.sun.xml.writer.template" "stw")
99 ("application/vnd.symbian.install" "sis")
100 ("application/vnd.visio" "vsd")
101 ("application/vnd.wap.wbxml" "wbxml")
102 ("application/vnd.wap.wmlc" "wmlc")
103 ("application/vnd.wap.wmlscriptc" "wmlsc")
104 ("application/x-123" "wk")
105 ("application/x-abiword" "abw")
106 ("application/x-apple-diskimage" "dmg")
107 ("application/x-bcpio" "bcpio")
108 ("application/x-bittorrent" "torrent")
109 ("application/x-cdf" "cdf")
110 ("application/x-cdlink" "vcd")
111 ("application/x-chess-pgn" "pgn")
112 ("application/x-cpio" "cpio")
113 ("application/x-csh" "csh")
114 ("application/x-debian-package" "deb" "udeb")
115 ("application/x-director" "dcr" "dir" "dxr")
116 ("application/x-dms" "dms")
117 ("application/x-doom" "wad")
118 ("application/x-dvi" "dvi")
119 ("application/x-flac" "flac")
120 ("application/x-font" "pfa" "pfb" "gsf" "pcf")
121 ("application/x-freemind" "mm")
122 ("application/x-futuresplash" "spl")
123 ("application/x-gnumeric" "gnumeric")
124 ("application/x-go-sgf" "sgf")
125 ("application/x-graphing-calculator" "gcf")
126 ("application/x-gtar" "gtar" "tgz" "taz")
127 ("application/x-hdf" "hdf")
128 ("application/x-httpd-php" "phtml" "pht" "php")
129 ("application/x-httpd-php-source" "phps")
130 ("application/x-httpd-php3" "php3")
131 ("application/x-httpd-php3-preprocessed" "php3p")
132 ("application/x-httpd-php4" "php4")
133 ("application/x-ica" "ica")
134 ("application/x-internet-signup" "ins" "isp")
135 ("application/x-iphone" "iii")
136 ("application/x-iso9660-image" "iso")
137 ("application/x-java-jnlp-file" "jnlp")
138 ("application/x-javascript" "js")
139 ("application/x-jmol" "jmz")
140 ("application/x-kchart" "chrt")
141 ("application/x-killustrator" "kil")
142 ("application/x-koan" "skp" "skd" "skt" "skm")
143 ("application/x-kpresenter" "kpr" "kpt")
144 ("application/x-kspread" "ksp")
145 ("application/x-kword" "kwd" "kwt")
146 ("application/x-latex" "latex")
147 ("application/x-lha" "lha")
148 ("application/x-lzh" "lzh")
149 ("application/x-lzx" "lzx")
150 ("application/x-maker" "frm" "maker" "frame" "fm" "fb" "book" "fbdoc")
151 ("application/x-mif" "mif")
152 ("application/x-ms-wmd" "wmd")
153 ("application/x-ms-wmz" "wmz")
154 ("application/x-msdos-program" "com" "exe" "bat" "dll")
155 ("application/x-msi" "msi")
156 ("application/x-netcdf" "nc")
157 ("application/x-ns-proxy-autoconfig" "pac")
158 ("application/x-nwc" "nwc")
159 ("application/x-object" "o")
160 ("application/x-oz-application" "oza")
161 ("application/x-pkcs7-certreqresp" "p7r")
162 ("application/x-pkcs7-crl" "crl")
163 ("application/x-python-code" "pyc" "pyo")
164 ("application/x-quicktimeplayer" "qtl")
165 ("application/x-redhat-package-manager" "rpm")
166 ("application/x-sh" "sh")
167 ("application/x-shar" "shar")
168 ("application/x-shockwave-flash" "swf" "swfl")
169 ("application/x-stuffit" "sit")
170 ("application/x-sv4cpio" "sv4cpio")
171 ("application/x-sv4crc" "sv4crc")
172 ("application/x-tar" "tar")
173 ("application/x-tcl" "tcl")
174 ("application/x-tex-gf" "gf")
175 ("application/x-tex-pk" "pk")
176 ("application/x-texinfo" "texinfo" "texi")
177 ("application/x-trash" "~%" "" "bak" "old" "sik")
178 ("application/x-troff" "tt" "r" "roff")
179 ("application/x-troff-man" "man")
180 ("application/x-troff-me" "me")
181 ("application/x-troff-ms" "ms")
182 ("application/x-ustar" "ustar")
183 ("application/x-wais-source" "src")
184 ("application/x-wingz" "wz")
185 ("application/x-x509-ca-cert" "crt")
186 ("application/x-xcf" "xcf")
187 ("application/x-xfig" "fig")
188 ("application/x-xpinstall" "xpi")
189 ("audio/basic" "au" "snd")
190 ("audio/midi" "mid" "midi" "kar")
191 ("audio/mpeg" "mpga" "mpega" "mp2" "mp3" "m4a")
192 ("audio/mpegurl" "m3u")
193 ("audio/prs.sid" "sid")
194 ("audio/x-aiff" "aif" "aiff" "aifc")
195 ("audio/x-gsm" "gsm")
196 ("audio/x-mpegurl" "m3u")
197 ("audio/x-ms-wma" "wma")
198 ("audio/x-ms-wax" "wax")
199 ("audio/x-pn-realaudio" "ra" "rm" "ram")
200 ("audio/x-realaudio" "ra")
201 ("audio/x-scpls" "pls")
202 ("audio/x-sd2" "sd2")
203 ("audio/x-wav" "wav")
204 ("chemical/x-alchemy" "alc")
205 ("chemical/x-cache" "cac" "cache")
206 ("chemical/x-cache-csf" "csf")
207 ("chemical/x-cactvs-binary" "cbin" "cascii" "ctab")
208 ("chemical/x-cdx" "cdx")
209 ("chemical/x-cerius" "cer")
210 ("chemical/x-chem3d" "c3d")
211 ("chemical/x-chemdraw" "chm")
212 ("chemical/x-cif" "cif")
213 ("chemical/x-cmdf" "cmdf")
214 ("chemical/x-cml" "cml")
215 ("chemical/x-compass" "cpa")
216 ("chemical/x-crossfire" "bsd")
217 ("chemical/x-csml" "csml" "csm")
218 ("chemical/x-ctx" "ctx")
219 ("chemical/x-cxf" "cxf" "cef")
220 ("chemical/x-embl-dl-nucleotide" "emb" "embl")
221 ("chemical/x-galactic-spc" "spc")
222 ("chemical/x-gamess-input" "inp" "gam" "gamin")
223 ("chemical/x-gaussian-checkpoint" "fch" "fchk")
224 ("chemical/x-gaussian-cube" "cub")
225 ("chemical/x-gaussian-input" "gau" "gjc" "gjf")
226 ("chemical/x-gaussian-log" "gal")
227 ("chemical/x-gcg8-sequence" "gcg")
228 ("chemical/x-genbank" "gen")
229 ("chemical/x-hin" "hin")
230 ("chemical/x-isostar" "istr" "ist")
231 ("chemical/x-jcamp-dx" "jdx" "dx")
232 ("chemical/x-kinemage" "kin")
233 ("chemical/x-macmolecule" "mcm")
234 ("chemical/x-macromodel-input" "mmd" "mmod")
235 ("chemical/x-mdl-molfile" "mol")
236 ("chemical/x-mdl-rdfile" "rd")
237 ("chemical/x-mdl-rxnfile" "rxn")
238 ("chemical/x-mdl-sdfile" "sd" "sdf")
239 ("chemical/x-mdl-tgf" "tgf")
240 ("chemical/x-mmcif" "mcif")
241 ("chemical/x-mol2" "mol2")
242 ("chemical/x-molconn-Z" "b")
243 ("chemical/x-mopac-graph" "gpt")
244 ("chemical/x-mopac-input" "mop" "mopcrt" "mpc" "dat" "zmt")
245 ("chemical/x-mopac-out" "moo")
246 ("chemical/x-mopac-vib" "mvb")
247 ("chemical/x-ncbi-asn1" "asn")
248 ("chemical/x-ncbi-asn1-ascii" "prt" "ent")
249 ("chemical/x-ncbi-asn1-binary" "val" "aso")
250 ("chemical/x-ncbi-asn1-spec" "asn")
251 ("chemical/x-pdb" "pdb" "ent")
252 ("chemical/x-rosdal" "ros")
253 ("chemical/x-swissprot" "sw")
254 ("chemical/x-vamas-iso14976" "vms")
255 ("chemical/x-vmd" "vmd")
256 ("chemical/x-xtel" "xtel")
257 ("chemical/x-xyz" "xyz")
258 ("image/gif" "gif")
259 ("image/ief" "ief")
260 ("image/jpeg" "jpeg" "jpg" "jpe")
261 ("image/pcx" "pcx")
262 ("image/png" "png")
263 ("image/svg+xml" "svg" "svgz")
264 ("image/tiff" "tiff" "tif")
265 ("image/vnd.djvu" "djvu" "djv")
266 ("image/vnd.wap.wbmp" "wbmp")
267 ("image/x-cmu-raster" "ras")
268 ("image/x-coreldraw" "cdr")
269 ("image/x-coreldrawpattern" "pat")
270 ("image/x-coreldrawtemplate" "cdt")
271 ("image/x-corelphotopaint" "cpt")
272 ("image/x-icon" "ico")
273 ("image/x-jg" "art")
274 ("image/x-jng" "jng")
275 ("image/x-ms-bmp" "bmp")
276 ("image/x-photoshop" "psd")
277 ("image/x-portable-anymap" "pnm")
278 ("image/x-portable-bitmap" "pbm")
279 ("image/x-portable-graymap" "pgm")
280 ("image/x-portable-pixmap" "ppm")
281 ("image/x-rgb" "rgb")
282 ("image/x-xbitmap" "xbm")
283 ("image/x-xpixmap" "xpm")
284 ("image/x-xwindowdump" "xwd")
285 ("model/iges" "igs" "iges")
286 ("model/mesh" "msh" "mesh" "silo")
287 ("model/vrml" "wrl" "vrml")
288 ("text/calendar" "ics" "icz")
289 ("text/comma-separated-values" "csv")
290 ("text/css" "css")
291 ("text/h323" "323")
292 ("text/html" "html" "htm" "shtml")
293 ("text/iuls" "uls")
294 ("text/mathml" "mml")
295 ("text/plain" "asc" "txt" "text" "diff" "pot")
296 ("text/richtext" "rtx")
297 ("text/rtf" "rtf")
298 ("text/scriptlet" "sct" "wsc")
299 ("text/texmacs" "tm" "ts")
300 ("text/tab-separated-values" "tsv")
301 ("text/vnd.sun.j2me.app-descriptor" "jad")
302 ("text/vnd.wap.wml" "wml")
303 ("text/vnd.wap.wmlscript" "wmls")
304 ("text/x-bibtex" "bib")
305 ("text/x-boo" "boo")
306 ("text/x-c++hdr" "h++" "hpp" "hxx" "hh")
307 ("text/x-c++src" "c++" "cpp" "cxx" "cc")
308 ("text/x-chdr" "h")
309 ("text/x-component" "htc")
310 ("text/x-csh" "csh")
311 ("text/x-csrc" "c")
312 ("text/x-dsrc" "d")
313 ("text/x-haskell" "hs")
314 ("text/x-java" "java")
315 ("text/javascript" "js")
316 ("text/x-literate-haskell" "lhs")
317 ("text/x-moc" "moc")
318 ("text/x-pascal" "pp" "as")
319 ("text/x-pcs-gcd" "gcd")
320 ("text/x-perl" "pl" "pm")
321 ("text/x-python" "py")
322 ("text/x-setext" "etx")
323 ("text/x-sh" "sh")
324 ("text/x-tcl" "tcl" "tk")
325 ("text/x-tex" "tex" "ltx" "sty" "cls")
326 ("text/x-vcalendar" "vcs")
327 ("text/x-vcard" "vcf")
328 ("video/dl" "dl")
329 ("video/dv" "dif" "dv")
330 ("video/fli" "fli")
331 ("video/gl" "gl")
332 ("video/mpeg" "mpeg" "mpg" "mpe")
333 ("video/mp4" "mp4")
334 ("video/quicktime" "qt" "mov")
335 ("video/vnd.mpegurl" "mxu")
336 ("video/x-la-asf" "lsf" "lsx")
337 ("video/x-m4v" "m4v")
338 ("video/x-mng" "mng")
339 ("video/x-ms-asf" "asf" "asx")
340 ("video/x-ms-wm" "wm")
341 ("video/x-ms-wmv" "wmv")
342 ("video/x-ms-wmx" "wmx")
343 ("video/x-ms-wvx" "wvx")
344 ("video/x-msvideo" "avi")
345 ("video/x-sgi-movie" "movie")
346 ("x-conference/x-cooltalk" "ice")
347 ("x-world/x-vrml" "vrm" "vrml" "wrl"))
348 "An alist where the cars are MIME types and the cdrs are list
349 of file suffixes for the corresponding type.")
350
351 (defparameter *mime-type-hash*
352 (let ((hash (make-hash-table :test #'equalp)))
353 (loop for (type . suffixes) in *mime-type-list* do
354 (loop for suffix in suffixes do
355 (setf (gethash suffix hash) type)))
356 hash)
357 "A hash table which maps file suffixes to MIME types.")
358
359 (defun mime-type (pathspec)
360 "Given a pathname designator PATHSPEC returns the MIME type
361 \(as a string) corresponding to the suffix of the file denoted by
362 PATHSPEC \(or NIL)."
363 (gethash (pathname-type pathspec) *mime-type-hash*))