Skip to content
Myr

Added res.download()

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 d12f434 · Browse files · 2 files+39 added−1 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+39 added−1 removed

  • tests:+26 added−0 removed
  • other:+13 added−1 removed

2 files+39 added−1 removed

modified:lib/express/response.js+13 added-1 removed
108 unmodified lines
109 }110 });111};112113113/**114 * Set _Content-Type_ response header passed through `mime.type()`.115 *116 * Examples:
26 unmodified lines
143 return this;144};145146/**147 * Transfer the given `file` with optional `filename` as an attachment.148 *149 * @param {String} file150 * @param {String} filename151 * @return {Type}152 * @api public153 */154155http.ServerResponse.prototype.download = function(file, filename){156 this.attachment(filename || path.basename(file)).sendfile(file);157};158159/**160 * Set or get response header `name` with optional `val`.161 *162 * @param {String} name163 * @param {String} val
72 unmodified lines
modified:test/response.test.js+26 added
189 unmodified lines
190 { body: 'Not Found', status: 404 });191 assert.response(app,192 { url: '/partials' },193 { body: 'Internal Server Error', status: 500 });194 },195 196 '#download()': function(assert){197 var app = express.createServer();198 199 app.get('/json', function(req, res, params, next){200 res.download(__dirname + '/fixtures/user.json', 'account.json');201 });202203 app.get('/:file', function(req, res, params, next){204 res.download(__dirname + '/fixtures/' + params.file);205 });206 207 assert.response(app,208 { url: '/user.json' },209 { body: '{"name":"tj"}', status: 200, headers: {210 'Content-Type': 'application/json',211 'Content-Disposition': 'attachment; filename="user.json"'212 }});213214 assert.response(app,215 { url: '/json' },216 { body: '{"name":"tj"}', status: 200, headers: {217 'Content-Type': 'application/json',218 'Content-Disposition': 'attachment; filename="account.json"'219 }});220 }221};