@@ -18,6 +18,7 @@ var encodeUrl = require('encodeurl');
1818var escapeHtml = require ( 'escape-html' ) ;
1919var http = require ( 'http' ) ;
2020var onFinished = require ( 'on-finished' ) ;
21+ var mime = require ( 'mime-types' )
2122var path = require ( 'path' ) ;
2223var pathIsAbsolute = require ( 'path-is-absolute' ) ;
2324var statuses = require ( 'statuses' )
@@ -29,7 +30,6 @@ var setCharset = require('./utils').setCharset;
2930var cookie = require ( 'cookie' ) ;
3031var send = require ( 'send' ) ;
3132var extname = path . extname ;
32- var mime = send . mime ;
3333var resolve = path . resolve ;
3434var vary = require ( 'vary' ) ;
3535
@@ -47,13 +47,6 @@ var res = Object.create(http.ServerResponse.prototype)
4747
4848module . exports = res
4949
50- /**
51- * Module variables.
52- * @private
53- */
54-
55- var charsetRegExp = / ; \s * c h a r s e t \s * = / ;
56-
5750/**
5851 * Set status `code`.
5952 *
@@ -451,8 +444,10 @@ res.download = function download (path, filename, options, callback) {
451444} ;
452445
453446/**
454- * Set _Content-Type_ response header with `type` through `mime.lookup ()`
447+ * Set _Content-Type_ response header with `type` through `mime.contentType ()`
455448 * when it does not contain "/", or set the Content-Type to `type` otherwise.
449+ * When no mapping is found though `mime.contentType()`, the type is set to
450+ * "application/octet-stream".
456451 *
457452 * Examples:
458453 *
@@ -470,7 +465,7 @@ res.download = function download (path, filename, options, callback) {
470465res . contentType =
471466res . type = function contentType ( type ) {
472467 var ct = type . indexOf ( '/' ) === - 1
473- ? mime . lookup ( type )
468+ ? ( mime . contentType ( type ) || 'application/octet-stream' )
474469 : type ;
475470
476471 return this . set ( 'Content-Type' , ct ) ;
@@ -621,6 +616,9 @@ res.append = function append(field, val) {
621616 *
622617 * Aliased as `res.header()`.
623618 *
619+ * When the set header is "Content-Type", the type is expanded to include
620+ * the charset if not present using `mime.contentType()`.
621+ *
624622 * @param {String|Object } field
625623 * @param {String|Array } val
626624 * @return {ServerResponse } for chaining
@@ -639,10 +637,7 @@ res.header = function header(field, val) {
639637 if ( Array . isArray ( value ) ) {
640638 throw new TypeError ( 'Content-Type cannot be set to an Array' ) ;
641639 }
642- if ( ! charsetRegExp . test ( value ) ) {
643- var charset = mime . charsets . lookup ( value . split ( ';' ) [ 0 ] ) ;
644- if ( charset ) value += '; charset=' + charset . toLowerCase ( ) ;
645- }
640+ value = mime . contentType ( value )
646641 }
647642
648643 this . setHeader ( field , value ) ;
0 commit comments