mime() is no longer global. Renamed to exports.type()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 944f99a · Browse files · 5 files·+44 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+44 added−37 removed
- tests:+33 added−25 removed
- other:+11 added−12 removed
Provenance
- Commit
2a4f352- Tree
b9b05e7- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
944f99a
5 files changed+44 added−37 removed
modified:lib/express/core.js-1 removed
5 unmodified lines6 process.mixin(require('express/collection'))7 process.mixin(require('express/event'))8 process.mixin(require('express/request'))9 process.mixin(require('express/plugin'))10-process.mixin(require('express/mime'))10 process.mixin(require('express/dsl'))11 12 /**13 * Module dependencies.319 unmodified linesmodified:lib/express/mime.js+6 added-5 removed
348 unmodified lines349 * By default 'application/octet-stream' is returned,350 * however this can be altered using the 'default mime type'351 * setting.352 *353- * mime('png') // => 'image/png'354- * mime('.png') // => 'image/png'355- * mime('image.png') // => 'image/png'356- * mime('path/to/image.png') // => 'image/png'353+ * var mime = require('express/mime')354+ * mime.type('png') // => 'image/png'355+ * mime.type('.png') // => 'image/png'356+ * mime.type('image.png') // => 'image/png'357+ * mime.type('path/to/image.png') // => 'image/png'358 *359 * @param {string} path360 * @return {string}361 * @settings 'default mime type'362 * @api public363 */364 364-exports.mime = function(path) {365+exports.type = function(path) {366 return exports.types[path] || 367 exports.types[utils.extname(path)] || 368 set('default mime type') || 369 'application/octet-stream' 1 unmodified linemodified:lib/express/request.js+5 added-6 removed
6 unmodified lines7 8 var StaticFile = require('express/static').File,9 statusBodies = require('http').STATUS_CODES,10 queryString = require('querystring'),11+ mime = require('express/mime'),12 url = require('url')13 14 // --- InvalidStatusCode15 96 unmodified lines112 },113 114 /**115 * Check if Accept header includes the mime type115- * for the given _path_, which calls mime().116+ * for the given _path_, which calls mime.type().117 *118 * When no Accept header is present true will be119 * returned as stated in the HTTP specification.120 *121 * @param {string} path122 * @return {bool}122- * @see mime()123 * @api public124 */125 126 accepts: function(path) {127 return this.header('accept') ? 128- this.header('accept').indexOf(mime(path)) !== -1 :128+ this.header('accept').indexOf(mime.type(path)) !== -1 :129 true130 },131 132 /**52 unmodified lines185 },186 187 /**188 * Set Content-Type header to the mime type189- * for the given _path_, which calls mime().189+ * for the given _path_, which calls mime.type().190 *191 * @param {string} path192 * @return {Request}193- * @see mime()193 * @api public194 */195 196 contentType: function(path) {198- this.header('content-type', mime(path))197+ this.header('content-type', mime.type(path))198 return this199 },200 201 /**61 unmodified linesmodified:spec/spec.mime.js+30 added-24 removed
12345678910117891012131415161712131415161819202122231819202122242526272829242526272829303132333435363738394031323334414243
describe 'Express' before mime = require('express/mime') end before_each reset() end describe 'mime' describe 'mime()' describe 'when given an extension with leading dot' it 'should return the associated mime type' mime('.png').should.eql 'image/png' describe 'type()' describe 'when given an extension with leading dot' it 'should return the associated mime type' mime.type('.png').should.eql 'image/png' end end end describe 'when given an extension without leading dot' it 'should return the associated mime type' mime('png').should.eql 'image/png'
describe 'when given an extension without leading dot' it 'should return the associated mime type' mime.type('png').should.eql 'image/png' end end end describe 'when given a file path' it 'should return the associated mime type' mime('/path/to/an/image.png').should.eql 'image/png'
describe 'when given a file path' it 'should return the associated mime type' mime.type('/path/to/an/image.png').should.eql 'image/png' end end end describe 'when given an unknown extension' it 'should default to the "default mime type" setting' set('default mime type', 'text/plain') mime('meow').should.eql 'text/plain'
describe 'when given an unknown extension' it 'should default to the "default mime type" setting' set('default mime type', 'text/plain') mime.type('meow').should.eql 'text/plain' end
it 'should default to "application/octet-stream" otherwise' mime.type('meow').should.eql 'application/octet-stream' end end it 'should default to "application/octet-stream" otherwise' mime('meow').should.eql 'application/octet-stream' end end endendNo newline at end of fileNo newline at end of filemodified:spec/spec.plugins.js+3 added-1 removed
123456789101110121314151625 unmodified lines
var mime = require('express/mime')
CSSColors = Plugin.extend({ extend: { init: function() { this.initialized = true } }, on: { response: function(event) { if (event.response.headers['content-type'] == mime('css')) if (event.response.headers['content-type'] == mime.type('css')) event.response.body = event.response.body.replace('black', '#000') } }})25 unmodified lines