Skip to content
Myr

Changed to allow extname or type/subtype only. Closes #1072

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 67ca22b · Browse files · 2 files+42 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+42 added−11 removed

  • tests:+31 added−0 removed
  • other:+11 added−11 removed

2 files+42 added−11 removed

modified:lib/response.js+11 added-11 removed
18 unmodified lines
19 , statusCodes = http.STATUS_CODES20 , send = connect.static.send21 , mime = require('mime')22 , basename = path.basename23 , extname = path.extname24 , join = path.join;2526/**27 * Response prototype.
236 unmodified lines
264 return this.attachment(filename || path).sendfile(path, fn);265};266267/**267 * Set _Content-Type_ response header passed through `mime.lookup()`.268 * Set _Content-Type_ response header with `type` through `mime.lookup()`269 * when it does not contain "/", or set the Content-Type to `type` otherwise.270 *271 * Examples:272 *271 * var filename = 'path/to/image.png';272 * res.contentType(filename);273 * // res.headers['Content-Type'] is now "image/png"274 *275 * res.contentType('.html');276 * res.contentType('html');277 * res.contentType('json');278 * res.contentType('png');273 * res.type('.html');274 * res.type('html');275 * res.type('json');276 * res.type('application/json');277 * res.type('png');278 *279 * @param {String} type280 * @return {ServerResponse} for chaining
1 unmodified line
282 */283284res.contentType =285res.type = function(type){288 return this.set('Content-Type', mime.lookup(type));286 return this.set('Content-Type', ~type.indexOf('/')287 ? type288 : mime.lookup(type));289};290291/**292 * Respond to the Acceptable formats using an `obj`
73 unmodified lines
366 * @api public367 */368369res.attachment = function(filename){370 if (filename) this.type(filename);370 if (filename) this.type(extname(filename));371 this.set('Content-Disposition', filename372 ? 'attachment; filename="' + basename(filename) + '"'373 : 'attachment');374 return this;
262 unmodified lines
modified:test/res.type.js+31 added