Skip to content
Browse files

mime() is no longer global. Renamed to exports.type()

  • Loading branch information...
1 parent 944f99a commit 2a4f3525d999c4a77c641be08f10fb854455c49f @tj tj committed
Showing with 44 additions and 37 deletions.
  1. +0 −1 lib/express/core.js
  2. +6 −5 lib/express/mime.js
  3. +5 −6 lib/express/request.js
  4. +30 −24 spec/spec.mime.js
  5. +3 −1 spec/spec.plugins.js
View
1 lib/express/core.js
@@ -7,7 +7,6 @@ process.mixin(require('express/collection'))
process.mixin(require('express/event'))
process.mixin(require('express/request'))
process.mixin(require('express/plugin'))
-process.mixin(require('express/mime'))
process.mixin(require('express/dsl'))
/**
View
11 lib/express/mime.js
@@ -350,10 +350,11 @@ exports.types = {
* however this can be altered using the 'default mime type'
* setting.
*
- * mime('png') // => 'image/png'
- * mime('.png') // => 'image/png'
- * mime('image.png') // => 'image/png'
- * mime('path/to/image.png') // => 'image/png'
+ * var mime = require('express/mime')
+ * mime.type('png') // => 'image/png'
+ * mime.type('.png') // => 'image/png'
+ * mime.type('image.png') // => 'image/png'
+ * mime.type('path/to/image.png') // => 'image/png'
*
* @param {string} path
* @return {string}
@@ -361,7 +362,7 @@ exports.types = {
* @api public
*/
-exports.mime = function(path) {
+exports.type = function(path) {
return exports.types[path] ||
exports.types[utils.extname(path)] ||
set('default mime type') ||
View
11 lib/express/request.js
@@ -8,6 +8,7 @@
var StaticFile = require('express/static').File,
statusBodies = require('http').STATUS_CODES,
queryString = require('querystring'),
+ mime = require('express/mime'),
url = require('url')
// --- InvalidStatusCode
@@ -112,20 +113,19 @@ exports.Request = Class({
/**
* Check if Accept header includes the mime type
- * for the given _path_, which calls mime().
+ * for the given _path_, which calls mime.type().
*
* When no Accept header is present true will be
* returned as stated in the HTTP specification.
*
* @param {string} path
* @return {bool}
- * @see mime()
* @api public
*/
accepts: function(path) {
return this.header('accept') ?
- this.header('accept').indexOf(mime(path)) !== -1 :
+ this.header('accept').indexOf(mime.type(path)) !== -1 :
true
},
@@ -186,16 +186,15 @@ exports.Request = Class({
/**
* Set Content-Type header to the mime type
- * for the given _path_, which calls mime().
+ * for the given _path_, which calls mime.type().
*
* @param {string} path
* @return {Request}
- * @see mime()
* @api public
*/
contentType: function(path) {
- this.header('content-type', mime(path))
+ this.header('content-type', mime.type(path))
return this
},
View
54 spec/spec.mime.js
@@ -1,36 +1,42 @@
describe 'Express'
+ before
+ mime = require('express/mime')
+ end
+
before_each
reset()
end
- describe 'mime()'
- describe 'when given an extension with leading dot'
- it 'should return the associated mime type'
- mime('.png').should.eql 'image/png'
+ describe 'mime'
+ 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'
- 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 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 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 a file path'
+ it 'should return the associated mime type'
+ mime.type('/path/to/an/image.png').should.eql 'image/png'
+ end
end
-
- it 'should default to "application/octet-stream" otherwise'
- mime('meow').should.eql 'application/octet-stream'
+
+ 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
end
end
View
4 spec/spec.plugins.js
@@ -1,4 +1,6 @@
+var mime = require('express/mime')
+
CSSColors = Plugin.extend({
extend: {
init: function() {
@@ -7,7 +9,7 @@ CSSColors = Plugin.extend({
},
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')
}
}

0 comments on commit 2a4f352

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