Skip to content

Commit

Permalink
Fix --ext with HTML (#590)
Browse files Browse the repository at this point in the history
Fix `--ext` with HTML
  • Loading branch information
thornjad committed Jan 6, 2020
2 parents a5db868 + a2de1cc commit b6934bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() : [];

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/root/htmlButNot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<h1>I am HTML?</h1>
<small>yeah i guess</small>
</div>
22 changes: 22 additions & 0 deletions test/http-server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit b6934bc

Please sign in to comment.