Express.Mime module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent e6c9318 · Browse files · 4 files·+222 added−186 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+222 added−186 removed
- tests:+6 added−4 removed
- other:+216 added−182 removed
Provenance
- Commit
92a43c5- Tree
f878f73- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
e6c9318
4 files changed+222 added−186 removed
modified:lib/express.mime.js+199 added-182 removed
123456789101112131415164567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
(function(){ Express.Mime = { name : 'mime', settings : { defaultMimeType : null }, utilities : { /** * Returns the media type of _ext_, where _ext_/** * Returns the media type of _ext_, where _ext_ * may be an extension ('jpeg') or a file path ('path/to/image.name.jpeg'). * * @param {string} ext * @return {string} * @api public */
Express.mime = function(ext) { if (ext.indexOf('.') != -1) ext = ext.substring(ext.lastIndexOf('.') + 1, ext.length) return Express.mimeTypes[ext] || 'application/octet-stream'}
Express.mimeTypes = { "3gp" : "video/3gpp", "a" : "application/octet-stream", "ai" : "application/postscript", "aif" : "audio/x-aiff", "aiff" : "audio/x-aiff", "asc" : "application/pgp-signature", "asf" : "video/x-ms-asf", "asm" : "text/x-asm", "asx" : "video/x-ms-asf", "atom" : "application/atom+xml", "au" : "audio/basic", "avi" : "video/x-msvideo", "bat" : "application/x-msdownload", "bin" : "application/octet-stream", "bmp" : "image/bmp", "bz2" : "application/x-bzip2", "c" : "text/x-c", "cab" : "application/vnd.ms-cab-compressed", "cc" : "text/x-c", "chm" : "application/vnd.ms-htmlhelp", "class" : "application/octet-stream", "com" : "application/x-msdownload", "conf" : "text/plain", "cpp" : "text/x-c", "crt" : "application/x-x509-ca-cert", "css" : "text/css", "csv" : "text/csv", "cxx" : "text/x-c", "deb" : "application/x-debian-package", "der" : "application/x-x509-ca-cert", "diff" : "text/x-diff", "djv" : "image/vnd.djvu", "djvu" : "image/vnd.djvu", "dll" : "application/x-msdownload", "dmg" : "application/octet-stream", "doc" : "application/msword", "dot" : "application/msword", "dtd" : "application/xml-dtd", "dvi" : "application/x-dvi", "ear" : "application/java-archive", "eml" : "message/rfc822", "eps" : "application/postscript", "exe" : "application/x-msdownload", "f" : "text/x-fortran", "f77" : "text/x-fortran", "f90" : "text/x-fortran", "flv" : "video/x-flv", "for" : "text/x-fortran", "gem" : "application/octet-stream", "gemspec" : "text/x-script.ruby", "gif" : "image/gif", "gz" : "application/x-gzip", "h" : "text/x-c", "hh" : "text/x-c", "htm" : "text/html", "html" : "text/html", "ico" : "image/vnd.microsoft.icon", "ics" : "text/calendar", "ifb" : "text/calendar", "iso" : "application/octet-stream", "jar" : "application/java-archive", "java" : "text/x-java-source", "jnlp" : "application/x-java-jnlp-file", "jpeg" : "image/jpeg", "jpg" : "image/jpeg", "js" : "application/javascript", "json" : "application/json", "log" : "text/plain", "m3u" : "audio/x-mpegurl", "m4v" : "video/mp4", "man" : "text/troff", "mathml" : "application/mathml+xml", "mbox" : "application/mbox", "mdoc" : "text/troff", "me" : "text/troff", "mid" : "audio/midi", "midi" : "audio/midi", "mime" : "message/rfc822", "mml" : "application/mathml+xml", "mng" : "video/x-mng", "mov" : "video/quicktime", "mp3" : "audio/mpeg", "mp4" : "video/mp4", "mp4v" : "video/mp4", "mpeg" : "video/mpeg", "mpg" : "video/mpeg", "ms" : "text/troff", "msi" : "application/x-msdownload", "odp" : "application/vnd.oasis.opendocument.presentation", "ods" : "application/vnd.oasis.opendocument.spreadsheet", "odt" : "application/vnd.oasis.opendocument.text", "ogg" : "application/ogg", "p" : "text/x-pascal", "pas" : "text/x-pascal", "pbm" : "image/x-portable-bitmap", "pdf" : "application/pdf", "pem" : "application/x-x509-ca-cert", "pgm" : "image/x-portable-graymap", "pgp" : "application/pgp-encrypted", "pkg" : "application/octet-stream", "pl" : "text/x-script.perl", "pm" : "text/x-script.perl-module", "png" : "image/png", "pnm" : "image/x-portable-anymap", "ppm" : "image/x-portable-pixmap", "pps" : "application/vnd.ms-powerpoint", "ppt" : "application/vnd.ms-powerpoint", "ps" : "application/postscript", "psd" : "image/vnd.adobe.photoshop", "py" : "text/x-script.python", "qt" : "video/quicktime", "ra" : "audio/x-pn-realaudio", "rake" : "text/x-script.ruby", "ram" : "audio/x-pn-realaudio", "rar" : "application/x-rar-compressed", "rb" : "text/x-script.ruby", "rdf" : "application/rdf+xml", "roff" : "text/troff", "rpm" : "application/x-redhat-package-manager", "rss" : "application/rss+xml", "rtf" : "application/rtf", "ru" : "text/x-script.ruby", "s" : "text/x-asm", "sgm" : "text/sgml", "sgml" : "text/sgml", "sh" : "application/x-sh", "sig" : "application/pgp-signature", "snd" : "audio/basic", "so" : "application/octet-stream", "svg" : "image/svg+xml", "svgz" : "image/svg+xml", "swf" : "application/x-shockwave-flash", "t" : "text/troff", "tar" : "application/x-tar", "tbz" : "application/x-bzip-compressed-tar", "tcl" : "application/x-tcl", "tex" : "application/x-tex", "texi" : "application/x-texinfo", "texinfo" : "application/x-texinfo", "text" : "text/plain", "tif" : "image/tiff", "tiff" : "image/tiff", "torrent" : "application/x-bittorrent", "tr" : "text/troff", "txt" : "text/plain", "vcf" : "text/x-vcard", "vcs" : "text/x-vcalendar", "vrml" : "model/vrml", "war" : "application/java-archive", "wav" : "audio/x-wav", "wma" : "audio/x-ms-wma", "wmv" : "video/x-ms-wmv", "wmx" : "video/x-ms-wmx", "wrl" : "model/vrml", "wsdl" : "application/wsdl+xml", "xbm" : "image/x-xbitmap", "xhtml" : "application/xhtml+xml", "xls" : "application/vnd.ms-excel", "xml" : "application/xml", "xpm" : "image/x-xpixmap", "xsl" : "application/xml", "xslt" : "application/xslt+xml", "yaml" : "text/yaml", "yml" : "text/yaml", "zip" : "application/zip"} * may be an extension ('jpeg') or a file path ('path/to/image.name.jpeg'). * * @param {string} ext * @return {string} * @api public */ mime : function(ext) { if (ext.indexOf('.') != -1) ext = ext.substring(ext.lastIndexOf('.') + 1, ext.length) return Express.utilities.mimeTypes[ext] || Express.settings.mime.defaultMimeType || 'application/octet-stream' }, mimeTypes : { "3gp" : "video/3gpp", "a" : "application/octet-stream", "ai" : "application/postscript", "aif" : "audio/x-aiff", "aiff" : "audio/x-aiff", "asc" : "application/pgp-signature", "asf" : "video/x-ms-asf", "asm" : "text/x-asm", "asx" : "video/x-ms-asf", "atom" : "application/atom+xml", "au" : "audio/basic", "avi" : "video/x-msvideo", "bat" : "application/x-msdownload", "bin" : "application/octet-stream", "bmp" : "image/bmp", "bz2" : "application/x-bzip2", "c" : "text/x-c", "cab" : "application/vnd.ms-cab-compressed", "cc" : "text/x-c", "chm" : "application/vnd.ms-htmlhelp", "class" : "application/octet-stream", "com" : "application/x-msdownload", "conf" : "text/plain", "cpp" : "text/x-c", "crt" : "application/x-x509-ca-cert", "css" : "text/css", "csv" : "text/csv", "cxx" : "text/x-c", "deb" : "application/x-debian-package", "der" : "application/x-x509-ca-cert", "diff" : "text/x-diff", "djv" : "image/vnd.djvu", "djvu" : "image/vnd.djvu", "dll" : "application/x-msdownload", "dmg" : "application/octet-stream", "doc" : "application/msword", "dot" : "application/msword", "dtd" : "application/xml-dtd", "dvi" : "application/x-dvi", "ear" : "application/java-archive", "eml" : "message/rfc822", "eps" : "application/postscript", "exe" : "application/x-msdownload", "f" : "text/x-fortran", "f77" : "text/x-fortran", "f90" : "text/x-fortran", "flv" : "video/x-flv", "for" : "text/x-fortran", "gem" : "application/octet-stream", "gemspec" : "text/x-script.ruby", "gif" : "image/gif", "gz" : "application/x-gzip", "h" : "text/x-c", "hh" : "text/x-c", "htm" : "text/html", "html" : "text/html", "ico" : "image/vnd.microsoft.icon", "ics" : "text/calendar", "ifb" : "text/calendar", "iso" : "application/octet-stream", "jar" : "application/java-archive", "java" : "text/x-java-source", "jnlp" : "application/x-java-jnlp-file", "jpeg" : "image/jpeg", "jpg" : "image/jpeg", "js" : "application/javascript", "json" : "application/json", "log" : "text/plain", "m3u" : "audio/x-mpegurl", "m4v" : "video/mp4", "man" : "text/troff", "mathml" : "application/mathml+xml", "mbox" : "application/mbox", "mdoc" : "text/troff", "me" : "text/troff", "mid" : "audio/midi", "midi" : "audio/midi", "mime" : "message/rfc822", "mml" : "application/mathml+xml", "mng" : "video/x-mng", "mov" : "video/quicktime", "mp3" : "audio/mpeg", "mp4" : "video/mp4", "mp4v" : "video/mp4", "mpeg" : "video/mpeg", "mpg" : "video/mpeg", "ms" : "text/troff", "msi" : "application/x-msdownload", "odp" : "application/vnd.oasis.opendocument.presentation", "ods" : "application/vnd.oasis.opendocument.spreadsheet", "odt" : "application/vnd.oasis.opendocument.text", "ogg" : "application/ogg", "p" : "text/x-pascal", "pas" : "text/x-pascal", "pbm" : "image/x-portable-bitmap", "pdf" : "application/pdf", "pem" : "application/x-x509-ca-cert", "pgm" : "image/x-portable-graymap", "pgp" : "application/pgp-encrypted", "pkg" : "application/octet-stream", "pl" : "text/x-script.perl", "pm" : "text/x-script.perl-module", "png" : "image/png", "pnm" : "image/x-portable-anymap", "ppm" : "image/x-portable-pixmap", "pps" : "application/vnd.ms-powerpoint", "ppt" : "application/vnd.ms-powerpoint", "ps" : "application/postscript", "psd" : "image/vnd.adobe.photoshop", "py" : "text/x-script.python", "qt" : "video/quicktime", "ra" : "audio/x-pn-realaudio", "rake" : "text/x-script.ruby", "ram" : "audio/x-pn-realaudio", "rar" : "application/x-rar-compressed", "rb" : "text/x-script.ruby", "rdf" : "application/rdf+xml", "roff" : "text/troff", "rpm" : "application/x-redhat-package-manager", "rss" : "application/rss+xml", "rtf" : "application/rtf", "ru" : "text/x-script.ruby", "s" : "text/x-asm", "sgm" : "text/sgml", "sgml" : "text/sgml", "sh" : "application/x-sh", "sig" : "application/pgp-signature", "snd" : "audio/basic", "so" : "application/octet-stream", "svg" : "image/svg+xml", "svgz" : "image/svg+xml", "swf" : "application/x-shockwave-flash", "t" : "text/troff", "tar" : "application/x-tar", "tbz" : "application/x-bzip-compressed-tar", "tcl" : "application/x-tcl", "tex" : "application/x-tex", "texi" : "application/x-texinfo", "texinfo" : "application/x-texinfo", "text" : "text/plain", "tif" : "image/tiff", "tiff" : "image/tiff", "torrent" : "application/x-bittorrent", "tr" : "text/troff", "txt" : "text/plain", "vcf" : "text/x-vcard", "vcs" : "text/x-vcalendar", "vrml" : "model/vrml", "war" : "application/java-archive", "wav" : "audio/x-wav", "wma" : "audio/x-ms-wma", "wmv" : "video/x-ms-wmv", "wmx" : "video/x-ms-wmx", "wrl" : "model/vrml", "wsdl" : "application/wsdl+xml", "xbm" : "image/x-xbitmap", "xhtml" : "application/xhtml+xml", "xls" : "application/vnd.ms-excel", "xml" : "application/xml", "xpm" : "image/x-xpixmap", "xsl" : "application/xml", "xslt" : "application/xslt+xml", "yaml" : "text/yaml", "yml" : "text/yaml", "zip" : "application/zip" } } } })()modified:lib/express.session.js+10 added
12345678910
// Express - Session - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
(function(){ Express.Session = { } })()No newline at end of filemodified:lib/express.view.js+7 added
1 2 // Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4+(function(){5+ 6+ Express.View = {7+ 8+ }9+ 10+})()modified:spec/spec.mime.js+6 added-4 removed
1 2+use(Express.Mime)3+4 describe 'Express'5 describe '.mime()'6 it 'should return media type of extensions passed'5- Express.mime('jpeg').should.eql 'image/jpeg'7+ Express.utilities.mime('jpeg').should.eql 'image/jpeg'8 end9 10 it 'should return application/octet-stream when invalid'9- Express.mime('foobar').should.eql 'application/octet-stream'11+ Express.utilities.mime('foobar').should.eql 'application/octet-stream'12 end13 14 it 'should parse extension of basename or path passed'13- Express.mime('images/profile.png').should.eql 'image/png'14- Express.mime('foo.bar.something-else.png').should.eql 'image/png'15+ Express.utilities.mime('images/profile.png').should.eql 'image/png'16+ Express.utilities.mime('foo.bar.something-else.png').should.eql 'image/png'17 end18 end19 end