Permalink
Browse files

Allows dynamic addition of content types #75

  • Loading branch information...
1 parent ed49feb commit fa3d5dea7b5d84d76153a897c1ca6131e1d71a87 @phstc phstc committed Dec 22, 2012
Showing with 26 additions and 11 deletions.
  1. +1 −0 lib/node-static.js
  2. +4 −0 lib/node-static/mime.js
  3. +21 −11 test/integration/node-static-test.js
View
1 lib/node-static.js
@@ -13,6 +13,7 @@ var util = require('./node-static/util');
// In-memory file store
exports.store = {};
exports.indexStore = {};
+exports.mime = mime;
exports.Server = function (root, options) {
if (root && (typeof(root) === 'object')) { options = root; root = null }
View
4 lib/node-static/mime.js
@@ -142,3 +142,7 @@ exports.contentTypes = {
"xyz": "chemical/x-pdb",
"zip": "application/zip"
};
+
+exports.addContentType = function(extension, contentType){
+ exports.contentTypes[extension] = contentType;
+};
View
32 test/integration/node-static-test.js
@@ -73,7 +73,7 @@ suite.addBatch({
'requesting a file not found': {
topic : function(){
request.get(TEST_SERVER + '/not-found', this.callback);
- },
+ },
'should respond with 404' : function(error, response, body){
assert.equal(response.statusCode, 404);
}
@@ -82,13 +82,13 @@ suite.addBatch({
'serving hello.txt': {
topic : function(){
request.get(TEST_SERVER + '/hello.txt', this.callback);
- },
+ },
'should respond with 200' : function(error, response, body){
assert.equal(response.statusCode, 200);
- },
+ },
'should respond with text/plain': function(error, response, body){
assert.equal(response.headers['content-type'], 'text/plain');
- },
+ },
'should respond with hello world': function(error, response, body){
assert.equal(body, 'hello world');
}
@@ -97,10 +97,10 @@ suite.addBatch({
'serving directory index': {
topic : function(){
request.get(TEST_SERVER, this.callback);
- },
+ },
'should respond with 200' : function(error, response, body){
assert.equal(response.statusCode, 200);
- },
+ },
'should respond with text/html': function(error, response, body){
assert.equal(response.headers['content-type'], 'text/html');
}
@@ -109,10 +109,10 @@ suite.addBatch({
'serving index.html from the cache': {
topic : function(){
request.get(TEST_SERVER + '/index.html', this.callback);
- },
+ },
'should respond with 200' : function(error, response, body){
assert.equal(response.statusCode, 200);
- },
+ },
'should respond with text/html': function(error, response, body){
assert.equal(response.headers['content-type'], 'text/html');
}
@@ -129,7 +129,7 @@ suite.addBatch({
},
_this.callback);
});
- },
+ },
'should respond with 304' : function(error, response, body){
assert.equal(response.statusCode, 304);
}
@@ -163,7 +163,7 @@ suite.addBatch({
},
'should respond with 200' : function(error, response, body){
assert.equal(response.statusCode, 200);
- },
+ },
'head must has no body' : function(error, response, body){
assert.isUndefined(body);
}
@@ -175,6 +175,16 @@ suite.addBatch({
},
'should respond with node-static/0.6.0' : function(error, response, body){
assert.equal(response.headers['server'], 'custom-server-name');
- }
+ }
+ }
+}).addBatch({
+ 'addings custom mime types': {
+ topic : function(){
+ static.mime.addContentType('woff', 'application/font-woff');
+ this.callback();
+ },
+ 'should add woff' : function(error, response, body){
+ assert.equal(static.mime.contentTypes['woff'], 'application/font-woff');
+ }
}
}).export(module);

0 comments on commit fa3d5de

Please sign in to comment.