diff --git a/bin/cli.js b/bin/cli.js index 659155d..b678643 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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([ @@ -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); + diff --git a/lib/node-static.js b/lib/node-static.js index 343baa6..136311b 100644 --- a/lib/node-static.js +++ b/lib/node-static.js @@ -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] || diff --git a/test/integration/node-static-test.js b/test/integration/node-static-test.js index 0bcb7d5..5501343 100644 --- a/test/integration/node-static-test.js +++ b/test/integration/node-static-test.js @@ -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'); @@ -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({ @@ -49,7 +51,7 @@ suite.addBatch({ } } }).addBatch({ - 'implicit serving index.html': { + 'serving directory index': { topic : function(){ request.get(TEST_SERVER, this.callback); }, @@ -101,4 +103,13 @@ suite.addBatch({ assert.isUndefined(body); } } -}).export(module); \ No newline at end of file +}).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);