Skip to content
Browse files

Fix invalid Content-Type header when send.mime.default_type unset

fixes #98
  • Loading branch information...
1 parent f840237 commit 31ceb6aaf530152c29a1855bf3f9dbd86533303e @dougwilson dougwilson committed
Showing with 24 additions and 1 deletion.
  1. +5 −0 HISTORY.md
  2. +10 −1 index.js
  3. +9 −0 test/send.js
View
5 HISTORY.md
@@ -1,3 +1,8 @@
+unreleased
+==========
+
+ * Fix invalid `Content-Type` header when `send.mime.default_type` unset
+
0.13.1 / 2016-01-16
===================
View
11 index.js
@@ -726,11 +726,20 @@ SendStream.prototype.stream = function(path, options){
* @api private
*/
-SendStream.prototype.type = function(path){
+SendStream.prototype.type = function type(path) {
var res = this.res;
+
if (res.getHeader('Content-Type')) return;
+
var type = mime.lookup(path);
+
+ if (!type) {
+ debug('no content-type');
+ return;
+ }
+
var charset = mime.charsets.lookup(type);
+
debug('content-type %s', type);
res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : ''));
};
View
9 test/send.js
@@ -1306,6 +1306,15 @@ describe('send.mime', function () {
.expect('Content-Type', 'text/plain; charset=UTF-8')
.expect(200, done)
})
+
+ it('should not add Content-Type for undefined default', function (done) {
+ send.mime.default_type = undefined
+
+ request(createServer({root: fixtures}))
+ .get('/nums')
+ .expect(shouldNotHaveHeader('Content-Type'))
+ .expect(200, done)
+ })
})
})

0 comments on commit 31ceb6a

Please sign in to comment.
Something went wrong with that request. Please try again.