Skip to content
Browse files

Added hottop/middleware.clj with function 'wrap-accept-from-extension…

…' and

associated test.
  • Loading branch information...
1 parent 6d845e1 commit ee651fe0ebe82ad133d09bc9acb4aeb622ff8549 @tmciver committed Jun 15, 2013
Showing with 859 additions and 0 deletions.
  1. +839 −0 src/hottop/middleware.clj
  2. +20 −0 test/hottop/test/middleware.clj
View
839 src/hottop/middleware.clj
@@ -0,0 +1,839 @@
+(ns hottop.middleware
+ (:require [clojure.string :as str]))
+
+(declare known-ct)
+
+(defn- get-extension
+ [s]
+ (last (str/split s #"\.")))
+
+(defn wrap-accept-from-extension
+ "Alters the 'Accept' header if the resource has an extension that is a key in
+the 'known-ct' map with the corresponding value."
+ [handler]
+ (fn [req]
+ (let [ext (last (str/split (:uri req) #"\."))]
+ (if-let [ct-from-ext (known-ct ext)]
+ ;; the extension was found in known-ct; add the corresponding media type
+ ;; to accept header
+ (handler (assoc-in req [:headers "accept"] ct-from-ext))
+ {:status 406 :body "Unsupported file extension"}))))
+
+;; The following data obtained from http://www.stdicon.com/mimetypes
+(def known-ct {"ksh" "text/plain",
+ "xlt" "application/vnd.ms-excel",
+ "davmount" "application/davmount+xml",
+ "vis" "application/vnd.visionary",
+ "cc" "text/x-c",
+ "ser" "application/java-serialized-object",
+ "wmv" "video/x-ms-wmv",
+ "sfs" "application/vnd.spotfire.sfs",
+ "xpx" "application/vnd.intercon.formnet",
+ "oa2" "application/vnd.fujitsu.oasys2",
+ "res" "application/x-dtbresource+xml",
+ "cif" "chemical/x-cif",
+ "hh" "text/x-c",
+ "gtm" "application/vnd.groove-tool-message",
+ "xpdl" "application/xml",
+ "ogx" "application/ogg",
+ "csp" "application/vnd.commonspace",
+ "mgz" "application/vnd.proteus.magazine",
+ "xlam" "application/vnd.ms-excel.addin.macroenabled.12",
+ "docx" "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ "txd" "application/vnd.genomatix.tuxedo",
+ "pqa" "application/vnd.palm",
+ "uu" "text/x-uuencode",
+ "hbci" "application/vnd.hbci",
+ "mpc" "application/vnd.mophun.certificate",
+ "msf" "application/vnd.epson.msf",
+ "lrf" "application/octet-stream",
+ "deb" "application/x-debian-package",
+ "mxl" "application/vnd.recordare.musicxml",
+ "scq" "application/scvp-cv-request",
+ "ecelp7470" "audio/vnd.nuera.ecelp7470",
+ "a" "application/octet-stream",
+ "acc" "application/vnd.americandynamics.acc",
+ "oa3" "application/vnd.fujitsu.oasys3",
+ "htm" "text/html",
+ "oas" "application/vnd.fujitsu.oasys",
+ "pct" "image/x-pict",
+ "list3820" "application/vnd.ibm.modcap",
+ "com" "application/x-msdownload",
+ "ext" "application/vnd.novadigm.ext",
+ "rs" "application/rls-services+xml",
+ "twd" "application/vnd.simtech-mindmapper",
+ "ppa" "application/vnd.ms-powerpoint",
+ "svd" "application/vnd.svd",
+ "prc" "application/x-mobipocket-ebook",
+ "psd" "image/vnd.adobe.photoshop",
+ "xdm" "application/vnd.syncml.dm+xml",
+ "midi" "audio/midi",
+ "otf" "application/x-font-otf",
+ "wcm" "application/vnd.ms-works",
+ "zip" "application/zip",
+ "nsf" "application/vnd.lotus-notes",
+ "fhc" "image/x-freehand",
+ "jpg" "image/jpeg",
+ "vxml" "application/voicexml+xml",
+ "aab" "application/x-authorware-bin",
+ "wmx" "video/x-ms-wmx",
+ "joda" "application/vnd.joost.joda-archive",
+ "pas" "text/x-pascal",
+ "sldm" "application/vnd.ms-powerpoint.slide.macroenabled.12",
+ "fh" "image/x-freehand",
+ "eol" "audio/vnd.digital-winds",
+ "spot" "text/vnd.in3d.spot",
+ "hvp" "application/vnd.yamaha.hv-voice",
+ "onetoc" "application/onenote",
+ "texi" "application/x-texinfo",
+ "cml" "chemical/x-cml",
+ "pfx" "application/x-pkcs12",
+ "xenc" "application/xenc+xml",
+ "java" "text/x-java-source",
+ "stc" "application/vnd.sun.xml.calc.template",
+ "acutc" "application/vnd.acucorp",
+ "txf" "application/vnd.mobius.txf",
+ "swf" "application/x-shockwave-flash",
+ "sxg" "application/vnd.sun.xml.writer.global",
+ "osf" "application/vnd.yamaha.openscoreformat",
+ "mpe" "video/mpeg",
+ "otg" "application/vnd.oasis.opendocument.graphics-template",
+ "kne" "application/vnd.kinar",
+ "ggb" "application/vnd.geogebra.file",
+ "msh" "model/mesh",
+ "mp4s" "application/mp4",
+ "tao" "application/vnd.tao.intent-module-archive",
+ "teacher" "application/vnd.smart.teacher",
+ "xlw" "application/vnd.ms-excel",
+ "xhtml" "application/xhtml+xml",
+ "rar" "application/x-rar-compressed",
+ "scs" "application/scvp-cv-response",
+ "viv" "video/vnd.vivo",
+ "hpid" "application/vnd.hp-hpid",
+ "dataless" "application/vnd.fdsn.seed",
+ "xlsb" "application/vnd.ms-excel.sheet.binary.macroenabled.12",
+ "aac" "audio/x-aac",
+ "c" "text/x-c",
+ "fli" "video/x-fli",
+ "ace" "application/x-ace-compressed",
+ "cii" "application/vnd.anser-web-certificate-issue-initiation",
+ "potx" "application/vnd.openxmlformats-officedocument.presentationml.template",
+ "ivp" "application/vnd.immervision-ivp",
+ "qfx" "application/vnd.intu.qfx",
+ "ncx" "application/x-dtbncx+xml",
+ "odft" "application/vnd.oasis.opendocument.formula-template",
+ "cpp" "text/x-c",
+ "tra" "application/vnd.trueapp",
+ "xslt" "application/xslt+xml",
+ "dts" "audio/vnd.dts",
+ "ttc" "application/x-font-ttf",
+ "css" "text/css",
+ "ps" "application/postscript",
+ "sv4crc" "application/x-sv4crc",
+ "qt" "video/quicktime",
+ "std" "application/vnd.sun.xml.draw.template",
+ "apr" "application/vnd.lotus-approach",
+ "rsd" "application/rsd+xml",
+ "cww" "application/prs.cww",
+ "cxx" "text/x-c",
+ "pre" "application/vnd.lotus-freelance",
+ "kia" "application/vnd.kidspiration",
+ "psf" "application/x-font-linux-psf",
+ "xbm" "image/x-xbitmap",
+ "oth" "application/vnd.oasis.opendocument.text-web",
+ "zir" "application/vnd.zul",
+ "msi" "application/x-msdownload",
+ "fgd" "application/x-director",
+ "fig" "application/x-xfig",
+ "sv4cpio" "application/x-sv4cpio",
+ "dfac" "application/vnd.dreamfactory",
+ "ipk" "application/vnd.shana.informed.package",
+ "ras" "image/x-cmu-raster",
+ "dotm" "application/vnd.ms-word.template.macroenabled.12",
+ "maker" "application/vnd.framemaker",
+ "irm" "application/vnd.ibm.rights-management",
+ "wmz" "application/x-ms-wmz",
+ "wsdl" "application/wsdl+xml",
+ "bdf" "application/x-font-bdf",
+ "pptx" "application/vnd.openxmlformats-officedocument.presentationml.presentation",
+ "eml" "message/rfc822",
+ "dll" "application/x-msdownload",
+ "urls" "text/uri-list",
+ "et3" "application/vnd.eszigno3+xml",
+ "fvt" "video/vnd.fvt",
+ "src" "application/x-wais-source",
+ "cst" "application/x-director",
+ "ppd" "application/vnd.cups-ppd",
+ "rtf" "application/rtf",
+ "svg" "image/svg+xml",
+ "c4u" "application/vnd.clonk.c4group",
+ "nnd" "application/vnd.noblenet-directory",
+ "prf" "application/pics-rules",
+ "sxi" "application/vnd.sun.xml.impress",
+ "mmd" "application/vnd.chipnuts.karaoke-mmd",
+ "org" "application/vnd.lotus-organizer",
+ "xdp" "application/vnd.adobe.xdp+xml",
+ "mpg" "video/mpeg",
+ "oti" "application/vnd.oasis.opendocument.image-template",
+ "conf" "text/plain",
+ "log" "text/plain",
+ "xht" "application/xhtml+xml",
+ "gif" "image/gif",
+ "cab" "application/vnd.ms-cab-compressed",
+ "ddd" "application/vnd.fujixerox.ddd",
+ "def" "text/plain",
+ "diff" "text/plain",
+ "cdf" "application/x-netcdf",
+ "lwp" "application/vnd.lotus-wordpro",
+ "ppsx""application/vnd.openxmlformats-officedocument.presentationml.slideshow",
+ "iso" "application/octet-stream",
+ "itp" "application/vnd.shana.informed.formtemplate",
+ "pcx" "image/x-pcx",
+ "atomcat" "application/atomcat+xml",
+ "h261" "video/h261",
+ "in" "text/plain",
+ "hvs" "application/vnd.yamaha.hv-script",
+ "wtb" "application/vnd.webturbo",
+ "es3" "application/vnd.eszigno3+xml",
+ "xwd" "image/x-xwindowdump",
+ "mpeg" "video/mpeg",
+ "bmp" "image/bmp",
+ "djvu" "image/vnd.djvu",
+ "crt" "application/x-x509-ca-cert",
+ "sse" "application/vnd.kodak-descriptor",
+ "stf" "application/vnd.wt.stf",
+ "lha" "application/octet-stream",
+ "karbon" "application/vnd.kde.karbon",
+ "swi" "application/vnd.arastra.swi",
+ "opf" "application/oebps-package+xml",
+ "atx" "application/vnd.antix.game-component",
+ "ifb" "text/calendar",
+ "aifc" "audio/x-aiff",
+ "qxl" "application/vnd.quark.quarkxpress",
+ "xer" "application/patch-ops-error+xml",
+ "ghf" "application/vnd.groove-help",
+ "xhvml" "application/xv+xml",
+ "mp4v" "video/mp4",
+ "tar" "application/x-tar",
+ "lvp" "audio/vnd.lucent.voice",
+ "sdw" "application/vnd.stardivision.writer",
+ "f" "text/x-fortran",
+ "cil" "application/vnd.ms-artgalry",
+ "gnumeric" "application/x-gnumeric",
+ "setpay" "application/set-payment-initiation",
+ "wmlsc" "application/vnd.wap.wmlscriptc",
+ "cmp" "application/vnd.yellowriver-custom-menu",
+ "shar" "application/x-shar",
+ "ms" "text/troff",
+ "dist" "application/octet-stream",
+ "onepkg" "application/onenote",
+ "spc" "application/x-pkcs7-certificates",
+ "f77" "text/x-fortran",
+ "plb" "application/vnd.3gpp.pic-bw-large",
+ "ttf" "application/x-font-ttf",
+ "csv" "text/csv",
+ "ssf" "application/vnd.epson.ssf",
+ "asx" "video/x-ms-asf",
+ "mmf" "application/vnd.smaf",
+ "iif" "application/vnd.shana.informed.interchange",
+ "htke" "application/vnd.kenameaapp",
+ "vcs" "text/x-vcalendar",
+ "sema" "application/vnd.sema",
+ "msl" "application/vnd.mobius.msl",
+ "p7m" "application/pkcs7-mime",
+ "pyo" "application/x-python-code",
+ "tex" "application/x-tex",
+ "ustar" "application/x-ustar",
+ "irp" "application/vnd.irepository.package+xml",
+ "tgz" "application/x-gzip",
+ "uris" "text/uri-list",
+ "fm" "application/vnd.framemaker",
+ "deploy" "application/octet-stream",
+ "h263" "video/h263",
+ "bin" "application/octet-stream",
+ "clp" "application/x-msclip",
+ "fst" "image/vnd.fst",
+ "vsd" "application/vnd.visio",
+ "chrt" "application/vnd.kde.kchart",
+ "cpt" "application/mac-compactpro",
+ "rnc" "application/relax-ng-compact-syntax",
+ "plc" "application/vnd.mobius.plc",
+ "xap" "application/x-silverlight-app",
+ "mathml" "application/mathml+xml",
+ "pwn" "application/vnd.3m.post-it-notes",
+ "lrm" "application/vnd.ms-lrm",
+ "jpm" "video/jpm",
+ "ksp" "application/vnd.kde.kspread",
+ "ai" "application/postscript",
+ "mxs" "application/vnd.triscape.mxs",
+ "h" "text/x-c",
+ "jpeg" "image/jpeg",
+ "kwt" "application/vnd.kde.kword",
+ "rdz" "application/vnd.data-vision.rdz",
+ "chm" "application/vnd.ms-htmlhelp",
+ "ivu" "application/vnd.immervision-ivu",
+ "json" "application/json",
+ "afm" "application/x-font-type1",
+ "h264" "video/h264",
+ "eps" "application/postscript",
+ "w3d" "application/x-director",
+ "f4v" "video/x-f4v",
+ "jnlp" "application/x-java-jnlp-file",
+ "sti" "application/vnd.sun.xml.impress.template",
+ "mid" "audio/midi",
+ "sxm" "application/vnd.sun.xml.math",
+ "aiff" "audio/x-aiff",
+ "wbs" "application/vnd.criticaltools.wbs+xml",
+ "otm" "application/vnd.oasis.opendocument.text-master",
+ "fdf" "application/vnd.fdf",
+ "ecelp9600" "audio/vnd.nuera.ecelp9600",
+ "wiz" "application/msword",
+ "ktr" "application/vnd.kahootz",
+ "flo" "application/vnd.micrografx.flo",
+ "cgm" "image/cgm",
+ "for" "text/x-fortran",
+ "gqs" "application/vnd.grafeq",
+ "x3d" "application/vnd.hzn-3d-crossword",
+ "dot" "application/msword",
+ "js" "application/javascript",
+ "vsf" "application/vnd.vsf",
+ "rlc" "image/vnd.fujixerox.edmics-rlc",
+ "mobi" "application/x-mobipocket-ebook",
+ "snd" "audio/basic",
+ "oga" "audio/ogg",
+ "etx" "text/x-setext",
+ "spf" "application/vnd.yamaha.smaf-phrase",
+ "py" "text/x-python",
+ "png" "image/png",
+ "icc" "application/vnd.iccprofile",
+ "xar" "application/vnd.xara",
+ "gac" "application/vnd.groove-account",
+ "book" "application/vnd.framemaker",
+ "semd" "application/vnd.semd",
+ "daf" "application/vnd.mobius.daf",
+ "clkk" "application/vnd.crick.clicker.keyboard",
+ "mxu" "video/vnd.mpegurl",
+ "mxml" "application/xv+xml",
+ "wqd" "application/vnd.wqd",
+ "dms" "application/octet-stream",
+ "eot" "application/vnd.ms-fontobject",
+ "gtw" "model/vnd.gtw",
+ "slc" "application/vnd.wap.slc",
+ "air" "application/vnd.adobe.air-application-installer-package+zip",
+ "rld" "application/resource-lists-diff+xml",
+ "pic" "image/x-pict",
+ "plf" "application/vnd.pocketlearn",
+ "stk" "application/hyperstudio",
+ "mif" "application/vnd.mif",
+ "ief" "image/ief",
+ "hdf" "application/x-hdf",
+ "mpm" "application/vnd.blueice.multipass",
+ "kml" "application/vnd.google-earth.kml+xml",
+ "sdkd" "application/vnd.solent.sdkm+xml",
+ "kon" "application/vnd.kde.kontour",
+ "nws" "message/rfc822",
+ "wma" "audio/x-ms-wma",
+ "hps" "application/vnd.hp-hps",
+ "bdm" "application/vnd.syncml.dm+wbxml",
+ "wpd" "application/vnd.wordperfect",
+ "grv" "application/vnd.groove-injector",
+ "afp" "application/vnd.ibm.modcap",
+ "pfa" "application/x-font-type1",
+ "snf" "application/x-font-snf",
+ "mdb" "application/x-msaccess",
+ "portpkg" "application/vnd.macports.portpkg",
+ "box" "application/vnd.previewsystems.box",
+ "stl" "application/vnd.ms-pki.stl",
+ "ice" "x-conference/x-cooltalk",
+ "msty" "application/vnd.muvee.style",
+ "xdw" "application/vnd.fujixerox.docuworks",
+ "mpn" "application/vnd.mophun.application",
+ "otp" "application/vnd.oasis.opendocument.presentation-template",
+ "vcx" "application/vnd.vcx",
+ "semf" "application/vnd.semf",
+ "p7r" "application/x-pkcs7-certreqresp",
+ "html" "text/html",
+ "oxt" "application/vnd.openofficeorg.extension",
+ "gim" "application/vnd.groove-identity-message",
+ "mus" "application/vnd.musician",
+ "dp" "application/vnd.osgi.dp",
+ "g3" "image/g3fax",
+ "jpgm" "video/jpm",
+ "bh2" "application/vnd.fujitsu.oasysprs",
+ "aep" "application/vnd.audiograph",
+ "skd" "application/vnd.koan",
+ "oda" "application/oda",
+ "pfb" "application/x-font-type1",
+ "smf" "application/vnd.stardivision.math",
+ "uri" "text/uri-list",
+ "wbxml" "application/vnd.wap.wbxml",
+ "pkg" "application/octet-stream",
+ "ppam" "application/vnd.ms-powerpoint.addin.macroenabled.12",
+ "curl" "text/vnd.curl",
+ "iges" "model/iges",
+ "cmdf" "chemical/x-cmdf",
+ "wav" "audio/x-wav",
+ "grxml" "application/srgs+xml",
+ "udeb" "application/x-debian-package",
+ "p7s" "application/pkcs7-signature",
+ "mts" "model/vnd.mts",
+ "imp" "application/vnd.accpac.simply.imp",
+ "hlp" "application/winhlp",
+ "aam" "application/x-authorware-map",
+ "xltm" "application/vnd.ms-excel.template.macroenabled.12",
+ "dir" "application/x-director",
+ "sldx" "application/vnd.openxmlformats-officedocument.presentationml.slide",
+ "adp" "audio/adpcm",
+ "rgb" "image/x-rgb",
+ "sic" "application/vnd.wap.sic",
+ "odb" "application/vnd.oasis.opendocument.database",
+ "text" "text/plain",
+ "frame" "application/vnd.framemaker",
+ "pclxl" "application/vnd.hp-pclxl",
+ "boz" "application/x-bzip2",
+ "mesh" "model/mesh",
+ "jad" "text/vnd.sun.j2me.app-descriptor",
+ "ppm" "image/x-portable-pixmap",
+ "nml" "application/vnd.enliven",
+ "wmlc" "application/vnd.wap.wmlc",
+ "mpp" "application/vnd.ms-project",
+ "qxt" "application/vnd.quark.quarkxpress",
+ "azf" "application/vnd.airzip.filesecure.azf",
+ "knp" "application/vnd.kinar",
+ "listafp" "application/vnd.ibm.modcap",
+ "pyv" "video/vnd.ms-playready.media.pyv",
+ "kpr" "application/vnd.kde.kpresenter",
+ "xla" "application/vnd.ms-excel",
+ "hpgl" "application/vnd.hp-hpgl",
+ "sbml" "application/sbml+xml",
+ "xlsm" "application/vnd.ms-excel.sheet.macroenabled.12",
+ "wmd" "application/x-ms-wmd",
+ "dis" "application/vnd.mobius.dis",
+ "fpx" "image/vnd.fpx",
+ "pdb" "application/vnd.palm",
+ "wri" "application/x-mswrite",
+ "odc" "application/vnd.oasis.opendocument.chart",
+ "cmx" "image/x-cmx",
+ "mcd" "application/vnd.mcd",
+ "rmi" "audio/midi",
+ "wbmp" "image/vnd.wap.wbmp",
+ "lbd" "application/vnd.llamagraphics.life-balance.desktop",
+ "pki" "application/pkixcmp",
+ "kil" "application/x-killustrator",
+ "wax" "audio/x-ms-wax",
+ "igl" "application/vnd.igloader",
+ "wspolicy" "application/wspolicy+xml",
+ "qwt" "application/vnd.quark.quarkxpress",
+ "ots" "application/vnd.oasis.opendocument.spreadsheet-template",
+ "clkp" "application/vnd.crick.clicker.palette",
+ "edm" "application/vnd.novadigm.edm",
+ "m4u" "video/vnd.mpegurl",
+ "xlb" "application/vnd.ms-excel",
+ "dotx" "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
+ "o" "application/octet-stream",
+ "hqx" "application/mac-binhex40",
+ "gv" "text/vnd.graphviz",
+ "btif" "image/prs.btif",
+ "rif" "application/reginfo+xml",
+ "xul" "application/vnd.mozilla.xul+xml",
+ "xvm" "application/xv+xml",
+ "ecelp4800" "audio/vnd.nuera.ecelp4800",
+ "smi" "application/smil+xml",
+ "ogg" "audio/ogg",
+ "lbe" "application/vnd.llamagraphics.life-balance.exchange+xml",
+ "spl" "application/x-futuresplash",
+ "trm" "application/x-msterminal",
+ "rpm" "application/x-rpm",
+ "pml" "application/vnd.ctc-posml",
+ "csml" "chemical/x-csml",
+ "ra" "audio/x-pn-realaudio",
+ "pnm" "image/x-portable-anymap",
+ "p10" "application/pkcs10",
+ "mp2" "audio/mpeg",
+ "gdl" "model/vnd.gdl",
+ "ott" "application/vnd.oasis.opendocument.text-template",
+ "m13" "application/x-msmediaview",
+ "atomsvc" "application/atomsvc+xml",
+ "kpt" "application/vnd.kde.kpresenter",
+ "ims" "application/vnd.ms-ims",
+ "m3u" "audio/x-mpegurl",
+ "m4v" "video/x-m4v",
+ "xlc" "application/vnd.ms-excel",
+ "sda" "application/vnd.stardivision.draw",
+ "cer" "application/pkix-cert",
+ "wmf" "application/x-msmetafile",
+ "p" "text/x-pascal",
+ "flv" "video/x-flv",
+ "dcurl" "text/vnd.curl.dcurl",
+ "djv" "image/vnd.djvu",
+ "torrent" "application/x-bittorrent",
+ "application" "application/x-ms-application",
+ "tpl" "application/vnd.groove-tool-template",
+ "mpg4" "video/mp4",
+ "sc" "application/vnd.ibm.secure-container",
+ "txt" "text/plain",
+ "atc" "application/vnd.acucorp",
+ "ifm" "application/vnd.shana.informed.formdata",
+ "mp3" "audio/mpeg",
+ "movie" "video/x-sgi-movie",
+ "m14" "application/x-msmediaview",
+ "onetoc2" "application/onenote",
+ "mp4a" "audio/mp4",
+ "xfdf" "application/vnd.adobe.xfdf",
+ "3dml" "text/vnd.in3d.3dml",
+ "der" "application/x-x509-ca-cert",
+ "ktz" "application/vnd.kahootz",
+ "flw" "application/vnd.kde.kivio",
+ "xpi" "application/x-xpinstall",
+ "tif" "image/tiff",
+ "shf" "application/shf+xml",
+ "sig" "application/pgp-signature",
+ "xsl" "application/xml",
+ "obd" "application/x-msbinder",
+ "onetmp" "application/onenote",
+ "wrl" "model/vrml",
+ "odf" "application/vnd.oasis.opendocument.formula",
+ "atom" "application/atom+xml",
+ "str" "application/vnd.pg.format",
+ "xspf" "application/xspf+xml",
+ "sus" "application/vnd.sus-calendar",
+ "seed" "application/vnd.fdsn.seed",
+ "asc" "application/pgp-signature",
+ "p12" "application/x-pkcs12",
+ "mlp" "application/vnd.dolby.mlp",
+ "mp4" "video/mp4",
+ "mpt" "application/vnd.ms-project",
+ "geo" "application/vnd.dynageo",
+ "m2v" "video/mpeg",
+ "ei6" "application/vnd.pg.osasli",
+ "sdc" "application/vnd.stardivision.calc",
+ "gmx" "application/vnd.gmx",
+ "cu" "application/cu-seeme",
+ "flx" "text/vnd.fmi.flexstor",
+ "pbd" "application/vnd.powerbuilder6",
+ "umj" "application/vnd.umajin",
+ "mseq" "application/vnd.mseq",
+ "xsm" "application/vnd.syncml+xml",
+ "setreg" "application/set-registration-initiation",
+ "pdf" "application/pdf",
+ "odg" "application/vnd.oasis.opendocument.graphics",
+ "mdi" "image/vnd.ms-modi",
+ "dtb" "application/x-dtbook+xml",
+ "exe" "application/x-msdownload",
+ "123" "application/vnd.lotus-1-2-3",
+ "dxf" "image/vnd.dxf",
+ "twds" "application/vnd.simtech-mindmapper",
+ "rss" "application/rss+xml",
+ "latex" "application/x-latex",
+ "sxw" "application/vnd.sun.xml.writer",
+ "ecma" "application/ecmascript",
+ "mmr" "image/vnd.fujixerox.edmics-mmr",
+ "mp2a" "audio/mpeg",
+ "jlt" "application/vnd.hp-jlyt",
+ "m1v" "video/mpeg",
+ "clkt" "application/vnd.crick.clicker.template",
+ "dd2" "application/vnd.oma.dd2+xml",
+ "fh4" "image/x-freehand",
+ "oprc" "application/vnd.palm",
+ "musicxml" "application/vnd.recordare.musicxml+xml",
+ "sdd" "application/vnd.stardivision.impress",
+ "see" "application/vnd.seemail",
+ "aas" "application/x-authorware-seg",
+ "s" "text/x-asm",
+ "fly" "text/vnd.fly",
+ "acu" "application/vnd.acucobol",
+ "wpl" "application/vnd.ms-wpl",
+ "pcf" "application/x-font-pcf",
+ "gz" "application/x-gzip",
+ "mag" "application/vnd.ecowin.chart",
+ "spp" "application/scvp-vp-response",
+ "dwf" "model/vnd.dwf",
+ "zaz" "application/vnd.zzazz.deck+xml",
+ "cpio" "application/x-cpio",
+ "c4d" "application/vnd.clonk.c4group",
+ "lostxml" "application/lost+xml",
+ "pps" "application/vnd.ms-powerpoint",
+ "icm" "application/vnd.iccprofile",
+ "nns" "application/vnd.noblenet-sealer",
+ "sgml" "text/sgml",
+ "pkipath" "application/pkix-pkipath",
+ "fe_launch" "application/vnd.denovo.fcselayout-link",
+ "pwz" "application/vnd.ms-powerpoint",
+ "sdkm" "application/vnd.solent.sdkm+xml",
+ "fh5" "image/x-freehand",
+ "dcr" "application/x-director",
+ "ufd" "application/vnd.ufdl",
+ "cct" "application/x-director",
+ "scd" "application/x-msschedule",
+ "au" "audio/basic",
+ "mime" "message/rfc822",
+ "t" "text/troff",
+ "rdf" "application/rdf+xml",
+ "odi" "application/vnd.oasis.opendocument.image",
+ "ma" "application/mathematica",
+ "u32" "application/x-authorware-bin",
+ "dsc" "text/prs.lines.tag",
+ "nb" "application/mathematica",
+ "spq" "application/scvp-vp-request",
+ "dtd" "application/xml-dtd",
+ "mfm" "application/vnd.mfmp",
+ "dump" "application/octet-stream",
+ "dwg" "image/vnd.dwg",
+ "qps" "application/vnd.publishare-delta-tree",
+ "kfo" "application/vnd.kde.kformula",
+ "ppt" "application/vnd.ms-powerpoint",
+ "asf" "video/x-ms-asf",
+ "avi" "video/x-msvideo",
+ "mov" "video/quicktime",
+ "fg5" "application/vnd.fujitsu.oasysgp",
+ "ggt" "application/vnd.geogebra.tool",
+ "distz" "application/octet-stream",
+ "car" "application/vnd.curl.car",
+ "bat" "application/x-msdownload",
+ "xpm" "image/x-xpixmap",
+ "ez" "application/andrew-inset",
+ "jpgv" "video/jpeg",
+ "skm" "application/vnd.koan",
+ "ftc" "application/vnd.fluxtime.clip",
+ "texinfo" "application/x-texinfo",
+ "mb" "application/mathematica",
+ "rmp" "audio/x-pn-realaudio-plugin",
+ "nc" "application/x-netcdf",
+ "bcpio" "application/x-bcpio",
+ "crd" "application/x-mscardfile",
+ "tiff" "image/tiff",
+ "docm" "application/vnd.ms-word.document.macroenabled.12",
+ "mj2" "video/mj2",
+ "sh" "application/x-sh",
+ "pot" "application/vnd.ms-powerpoint",
+ "c4f" "application/vnd.clonk.c4group",
+ "ico" "image/x-icon",
+ "igs" "model/iges",
+ "wdb" "application/vnd.ms-works",
+ "mqy" "application/vnd.mobius.mqy",
+ "clkw" "application/vnd.crick.clicker.wordbank",
+ "xif" "image/vnd.xiff",
+ "fh7" "image/x-freehand",
+ "cdxml" "application/vnd.chemdraw+xml",
+ "aw" "application/applixware",
+ "wml" "text/vnd.wap.wml",
+ "abw" "application/x-abiword",
+ "hvd" "application/vnd.yamaha.hv-dic",
+ "tmo" "application/vnd.tmobile-livetv",
+ "fsc" "application/vnd.fsc.weblaunch",
+ "pgm" "image/x-portable-graymap",
+ "vss" "application/vnd.visio",
+ "mbk" "application/vnd.mobius.mbk",
+ "jam" "application/vnd.jam",
+ "stw" "application/vnd.sun.xml.writer.template",
+ "si" "text/vnd.wap.si",
+ "c4g" "application/vnd.clonk.c4group",
+ "rtx" "text/richtext",
+ "svgz" "image/svg+xml",
+ "wm" "video/x-ms-wm",
+ "npx" "image/vnd.net-fpx",
+ "mpy" "application/vnd.ibm.minipay",
+ "clkx" "application/vnd.crick.clicker",
+ "cat" "application/vnd.ms-pki.seccat",
+ "xfdl" "application/vnd.xfdl",
+ "xml" "application/xml",
+ "cdx" "chemical/x-cdx",
+ "x32" "application/x-authorware-bin",
+ "obj" "application/octet-stream",
+ "dna" "application/vnd.dna",
+ "n-gage" "application/vnd.nokia.n-gage.symbian.install",
+ "pfm" "application/x-font-type1",
+ "pgn" "application/x-chess-pgn",
+ "vst" "application/vnd.visio",
+ "vtu" "model/vnd.vtu",
+ "zirz" "application/vnd.zul",
+ "tsv" "text/tab-separated-values",
+ "pls" "application/pls+xml",
+ "dvi" "application/x-dvi",
+ "gram" "application/srgs",
+ "nlu" "application/vnd.neurolanguage.nlu",
+ "nnw" "application/vnd.noblenet-web",
+ "xo" "application/vnd.olpc-sugar",
+ "fbs" "image/vnd.fastbidsheet",
+ "vcd" "application/x-cdlink",
+ "ccxml" "application/ccxml+xml",
+ "cdy" "application/vnd.cinderella",
+ "bz" "application/x-bzip",
+ "epub" "application/epub+zip",
+ "kwd" "application/vnd.kde.kword",
+ "xltx" "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
+ "sgl" "application/vnd.stardivision.writer-global",
+ "potm" "application/vnd.ms-powerpoint.template.macroenabled.12",
+ "cla" "application/vnd.claymore",
+ "skp" "application/vnd.koan",
+ "doc" "application/msword",
+ "cod" "application/vnd.rim.cod",
+ "esf" "application/vnd.epson.esf",
+ "class" "application/java-vm",
+ "tpt" "application/vnd.trid.tpt",
+ "mhtml" "message/rfc822",
+ "me" "text/troff",
+ "rms" "application/vnd.jcp.javame.midlet-rms",
+ "csh" "application/x-csh",
+ "rcprofile" "application/vnd.ipunplugged.rcprofile",
+ "mny" "application/x-msmoney",
+ "chat" "application/x-chat",
+ "kmz" "application/vnd.google-earth.kmz",
+ "pya" "audio/vnd.ms-playready.media.pya",
+ "saf" "application/vnd.yamaha.smaf-audio",
+ "mcurl" "text/vnd.curl.mcurl",
+ "xlsx" "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "xop" "application/xop+xml",
+ "pptm" "application/vnd.ms-powerpoint.presentation.macroenabled.12",
+ "xbap" "application/x-ms-xbap",
+ "sgm" "text/sgml",
+ "pcl" "application/vnd.hp-pcl",
+ "vor" "application/vnd.stardivision.writer",
+ "cmc" "application/vnd.cosmocaller",
+ "pgp" "application/pgp-encrypted",
+ "wvx" "video/x-ms-wvx",
+ "xyz" "chemical/x-xyz",
+ "uoml" "application/vnd.uoml+xml",
+ "srx" "application/sparql-results+xml",
+ "mht" "message/rfc822",
+ "sl" "text/vnd.wap.sl",
+ "silo" "model/mesh",
+ "ics" "text/calendar",
+ "ufdl" "application/vnd.ufdl",
+ "vcf" "text/x-vcard",
+ "edx" "application/vnd.novadigm.edx",
+ "mvb" "application/x-msmediaview",
+ "xlm" "application/vnd.ms-excel",
+ "link66" "application/vnd.route66.link66+xml",
+ "ppsm" "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
+ "xpr" "application/vnd.is-xpr",
+ "lzh" "application/octet-stream",
+ "wps" "application/vnd.ms-works",
+ "gre" "application/vnd.geometry-explorer",
+ "gsf" "application/x-font-ghostscript",
+ "man" "text/troff",
+ "vsw" "application/vnd.visio",
+ "les" "application/vnd.hhe.lesson-player",
+ "rl" "application/resource-lists+xml",
+ "xbd" "application/vnd.fujixerox.docuworks.binder",
+ "wad" "application/x-doom",
+ "bz2" "application/x-bzip2",
+ "igx" "application/vnd.micrografx.igx",
+ "gex" "application/vnd.geometry-explorer",
+ "vcg" "application/vnd.groove-vcard",
+ "sitx" "application/x-stuffitx",
+ "azs" "application/vnd.airzip.filesecure.azs",
+ "pyc" "application/x-python-code",
+ "zmm" "application/vnd.handheld-entertainment+xml",
+ "mxf" "application/mxf",
+ "tfm" "application/x-tex-tfm",
+ "xps" "application/vnd.ms-xpsdocument",
+ "fnc" "application/vnd.frogans.fnc",
+ "pbm" "image/x-portable-bitmap",
+ "odp" "application/vnd.oasis.opendocument.presentation",
+ "slt" "application/vnd.epson.salt",
+ "dpg" "application/vnd.dpgraph",
+ "fti" "application/vnd.anser-web-funds-transfer-initiation",
+ "mc1" "application/vnd.medcalcdata",
+ "vrml" "model/vrml",
+ "spx" "audio/ogg",
+ "utz" "application/vnd.uiq.theme",
+ "jar" "application/java-archive",
+ "rm" "application/vnd.rn-realmedia",
+ "asm" "text/x-asm",
+ "qxb" "application/vnd.quark.quarkxpress",
+ "sisx" "application/vnd.symbian.install",
+ "p7b" "application/x-pkcs7-certificates",
+ "m3a" "audio/mpeg",
+ "emma" "application/emma+xml",
+ "3gp" "video/3gpp",
+ "elc" "application/octet-stream",
+ "gqf" "application/vnd.grafeq",
+ "skt" "application/vnd.koan",
+ "pfr" "application/font-tdpfr",
+ "kar" "audio/midi",
+ "mscml" "application/mediaservercontrol+xml",
+ "pl" "text/plain",
+ "apk" "application/vnd.android.package-archive",
+ "dxp" "application/vnd.spotfire.dxp",
+ "so" "application/octet-stream",
+ "pcurl" "application/vnd.curl.pcurl",
+ "pvb" "application/vnd.3gpp.pic-bw-var",
+ "p7c" "application/pkcs7-mime",
+ "m2a" "audio/mpeg",
+ "jisp" "application/vnd.jisp",
+ "mwf" "application/vnd.mfer",
+ "scm" "application/vnd.lotus-screencam",
+ "qam" "application/vnd.epson.quickanime",
+ "rep" "application/vnd.businessobjects",
+ "sis" "application/vnd.symbian.install",
+ "smil" "application/smil+xml",
+ "xvml" "application/xv+xml",
+ "mpga" "audio/mpeg",
+ "ami" "application/vnd.amiga.ami",
+ "crl" "application/pkix-crl",
+ "bpk" "application/octet-stream",
+ "f90" "text/x-fortran",
+ "ez2" "application/vnd.ezpix-album",
+ "swa" "application/x-director",
+ "aso" "application/vnd.accpac.simply.aso",
+ "wmls" "text/vnd.wap.wmlscript",
+ "pub" "application/x-mspublisher",
+ "qxd" "application/vnd.quark.quarkxpress",
+ "roff" "text/troff",
+ "tcl" "application/x-tcl",
+ "ram" "audio/x-pn-realaudio",
+ "3g2" "video/3gpp2",
+ "mseed" "application/vnd.fdsn.mseed",
+ "dic" "text/x-c",
+ "qbo" "application/vnd.intu.qbo",
+ "list" "text/plain",
+ "sit" "application/x-stuffit",
+ "dmg" "application/octet-stream",
+ "rpss" "application/vnd.nokia.radio-presets",
+ "ods" "application/vnd.oasis.opendocument.spreadsheet",
+ "aif" "audio/x-aiff",
+ "efif" "application/vnd.picsel",
+ "bmi" "application/vnd.bmi",
+ "ogv" "video/ogg",
+ "gtar" "application/x-gtar",
+ "ez3" "application/vnd.ezpix-package",
+ "mbox" "application/mbox",
+ "dxr" "application/x-director",
+ "cdkey" "application/vnd.mediastation.cdkey",
+ "tr" "text/troff",
+ "sxc" "application/vnd.sun.xml.calc",
+ "tcap" "application/vnd.3gpp2.tcap",
+ "qwd" "application/vnd.quark.quarkxpress",
+ "mpa" "video/mpeg",
+ "otc" "application/vnd.oasis.opendocument.chart-template",
+ "ngdat" "application/vnd.nokia.n-gage.data",
+ "mrc" "application/marc",
+ "azw" "application/vnd.amazon.ebook",
+ "ltf" "application/vnd.frogans.ltf",
+ "mjp2" "video/mj2",
+ "wks" "application/vnd.ms-works",
+ "susp" "application/vnd.sus-calendar",
+ "sdp" "application/sdp",
+ "xpw" "application/vnd.intercon.formnet",
+ "gph" "application/vnd.flographit",
+ "osfpvg" "application/vnd.yamaha.openscoreformat.osfpvg+xml",
+ "vox" "application/x-authorware-bin",
+ "rpst" "application/vnd.nokia.radio-preset",
+ "scurl" "text/vnd.curl.scurl",
+ "odt" "application/vnd.oasis.opendocument.text",
+ "fzs" "application/vnd.fuzzysheet",
+ "dtshd" "audio/vnd.dts.hd",
+ "ptid" "application/vnd.pvi.ptid1",
+ "rq" "application/sparql-query",
+ "mpkg" "application/vnd.apple.installer+xml",
+ "c4p" "application/vnd.clonk.c4group",
+ "cxt" "application/x-director",
+ "sxd" "application/vnd.sun.xml.draw",
+ "psb" "application/vnd.3gpp.pic-bw-small",
+ "sfd-hdstx" "application/vnd.hydrostatix.sof-data",
+ "unityweb" "application/vnd.unity",
+ "jpe" "image/jpeg",
+ "cdbcmsg" "application/vnd.contact.cmsg",
+ "ssml" "application/ssml+xml",
+ "xls" "application/vnd.ms-excel"})
View
20 test/hottop/test/middleware.clj
@@ -0,0 +1,20 @@
+(ns hottop.test.middleware
+ (:use clojure.test
+ ring.mock.request
+ hottop.middleware))
+
+(deftest test-wrap-accept-from-extension
+ (let [handler (-> (fn [req]
+ ;; return the accept headers
+ (get-in req [:headers "accept"]))
+ wrap-accept-from-extension)
+ req1 (request :get "/test")
+ req2 (request :get "/test.zip")
+ req3 (request :get "/test.html")
+ req4 (request :get "/test.csv")
+ req5 (request :get "/test.abc")]
+ (is (handler req1) [])
+ (is (handler req2) #{"application/zip"})
+ (is (handler req3) #{"text/html"})
+ (is (handler req4) #{"text/csv"})
+ (is (handler req5) {:status 406 :body "Unsupported file extension"})))

0 comments on commit ee651fe

Please sign in to comment.
Something went wrong with that request. Please try again.