From b2bf05778865fd7d179fd7f7575ee7769356078e Mon Sep 17 00:00:00 2001 From: Jade Michael Thornton Date: Fri, 20 Dec 2019 08:46:52 -0600 Subject: [PATCH 1/2] add test for auto-ext --- test/fixtures/root/htmlButNot | 4 ++++ test/http-server-test.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/fixtures/root/htmlButNot 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); From a2de1ccf3a4d6cbfbb6cbc1c421f0cadeead0c52 Mon Sep 17 00:00:00 2001 From: Jade Michael Thornton Date: Fri, 20 Dec 2019 08:47:02 -0600 Subject: [PATCH 2/2] when ext is html, serve text/html content type --- lib/http-server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() : [];