[Pkg-javascript-commits] [node-static] 96/151: Allows dynamic addition of content types #75
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:18:01 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository node-static.
commit fa3d5dea7b5d84d76153a897c1ca6131e1d71a87
Author: Pablo Cantero <pablo at pablocantero.com>
Date: Fri Dec 21 22:46:17 2012 -0200
Allows dynamic addition of content types #75
---
lib/node-static.js | 1 +
lib/node-static/mime.js | 4 ++++
test/integration/node-static-test.js | 32 +++++++++++++++++++++-----------
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/lib/node-static.js b/lib/node-static.js
index d6775e7..53c3800 100644
--- a/lib/node-static.js
+++ b/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 }
diff --git a/lib/node-static/mime.js b/lib/node-static/mime.js
index 7308669..f427654 100644
--- a/lib/node-static/mime.js
+++ b/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;
+};
diff --git a/test/integration/node-static-test.js b/test/integration/node-static-test.js
index ae6d732..c183c3e 100644
--- a/test/integration/node-static-test.js
+++ b/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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git
More information about the Pkg-javascript-commits
mailing list