Skip to content

Commit

Permalink
Merging cloudhead#66
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Cantero committed Sep 16, 2012
1 parent 67b723b commit 788203a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bin/cli.js
Expand Up @@ -3,7 +3,7 @@
var fs = require('fs'),
path = require('path'),
tty = require('tty'),
statik = require('./../lib/node-static');
statik = require('./../lib/node-static');

var argv = require('optimist')
.usage([
Expand Down Expand Up @@ -101,3 +101,4 @@ require('http').createServer(function (request, response) {
}).listen(+argv.port);

console.log('serving "' + dir + '" at http://127.0.0.1:' + argv.port);

6 changes: 4 additions & 2 deletions lib/node-static.js
Expand Up @@ -31,16 +31,18 @@ this.Server = function (root, options) {
this.cache = false;
}
}

if ('serverInfo' in this.options) {
this.serverInfo = this.options.serverInfo.toString();
} else {
this.serverInfo = 'node-static/' + this.version.join('.');
this.serverInfo = 'node-static/' + exports.version.join('.');
}

this.defaultHeaders['Server'] = this.serverInfo;

if (this.cache !== false) {
this.defaultHeaders['Cache-Control'] = 'max-age=' + this.cache;
}
this.defaultHeaders['Server'] = this.serverInfo;

for (var k in this.defaultHeaders) {
this.options.headers[k] = this.options.headers[k] ||
Expand Down
19 changes: 15 additions & 4 deletions test/integration/node-static-test.js
Expand Up @@ -3,7 +3,7 @@ var vows = require('vows')
, assert = require('assert')
, static = require('../../lib/node-static');

var fileServer = new(static.Server)(__dirname + '/../fixtures', {});
var fileServer = new(static.Server)(__dirname + '/../fixtures', {serverInfo: "custom-server-name"});

var suite = vows.describe('node-static');

Expand All @@ -21,7 +21,9 @@ suite.addBatch({
}).listen(TEST_PORT, this.callback)
},
'should be listening' : function(){
assert.isTrue(true);
/* This test is necessary to ensure the topic execution.
* A topic without tests will be not executed */
assert.isTrue(true);
}
}
}).addBatch({
Expand Down Expand Up @@ -49,7 +51,7 @@ suite.addBatch({
}
}
}).addBatch({
'implicit serving index.html': {
'serving directory index': {
topic : function(){
request.get(TEST_SERVER, this.callback);
},
Expand Down Expand Up @@ -101,4 +103,13 @@ suite.addBatch({
assert.isUndefined(body);
}
}
}).export(module);
}).addBatch({
'requesting headers': {
topic : function(){
request.head(TEST_SERVER + '/index.html', this.callback);
},
'should respond with node-static/0.6.0' : function(error, response, body){
assert.equal(response.headers["server"], "custom-server-name");
}
}
}).export(module);

0 comments on commit 788203a

Please sign in to comment.