diff --git a/lib/http-server.js b/lib/http-server.js index 626a5a84..ab340d81 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -82,13 +82,13 @@ function HttpServer(options) { this.showDotfiles = options.showDotfiles; this.gzip = options.gzip === true; this.brotli = options.brotli === true; - this.contentType = options.contentType || 'application/octet-stream'; - if (options.ext) { this.ext = options.ext === true ? 'html' : options.ext; } + this.contentType = options.contentType || + this.ext === 'html' ? 'text/html' : 'application/octet-stream'; var before = options.before ? options.before.slice() : []; diff --git a/test/fixtures/root/htmlButNot b/test/fixtures/root/htmlButNot new file mode 100644 index 00000000..3d6a33f6 --- /dev/null +++ b/test/fixtures/root/htmlButNot @@ -0,0 +1,4 @@ +
+

I am HTML?

+ yeah i guess +
diff --git a/test/http-server-test.js b/test/http-server-test.js index 66ac644f..47026761 100644 --- a/test/http-server-test.js +++ b/test/http-server-test.js @@ -357,5 +357,27 @@ vows.describe('http-server').addBatch({ teardown: function (server) { server.close(); } + }, + 'When auto-ext is enabled': { + topic: function () { + var server = httpServer.createServer({ + root: root, + ext: true + }); + server.listen(8085); + this.callback(null, server); + }, + 'and a file with no extension is requested with default options,': { + topic: function () { + request('http://127.0.0.1:8085/htmlButNot', this.callback); + }, + 'content-type should be text/html': function (res) { + assert.equal(res.statusCode, 200); + assert.match(res.headers['content-type'], /^text\/html/); + } + }, + teardown: function (server) { + server.close(); + } } }).export(module);