Skip to content
Myr

move Request#download to Static plugin

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

#download() was a hangover from before the Static plugin existed and no longer worked. Also added missing specs so this won't happen again.

authored by Aaron Heckmann · committed by Aaron Heckmann · parent 68f8ee8 · Browse files · 3 files+39 added−13 removed
This commit

State

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

Diff stats

3 files+39 added−13 removed

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

3 files+39 added−13 removed

modified:lib/express/plugins/static.js+13 added
modified:lib/express/request.js-13 removed
262 unmodified lines
263 return this264 },265 266 /**267 * Transfer static file at the given _path_ as an attachment.268 * The basename of _path_ is used as the attachment filename.269 *270 * @param {string} path271 * @return {Request}272 * @api public273 */274 275 download: function(path) {276 return this.attachment(basename(path)).sendfile(path)277 },278 279 /**267 * Set Content-Disposition header to 'attachment',268 * with optional file _path_.269 *270 * @param {string} path
76 unmodified lines
modified:spec/spec.plugins.static.js+26 added
72 unmodified lines
73 end74 end75 end76 77 describe '#download()' 78 describe 'when the file exists'79 it 'should set attachment filename'80 get('/report', function(){81 this.download('report.pdf')82 return 'foo'83 })84 get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'85 end86 87 it 'should transfer the file'88 get('/public/*', function(file){89 this.download('spec/fixtures/' + file)90 })91 get('/public/user.json').body.should.include '"name":'92 end93 94 it 'should automatically set the content type based on extension'95 get('/public/*', function(file){96 this.download('spec/fixtures/' + file)97 })98 get('/public/user.json').headers['content-type'].should.eql 'application/json'99 end100 end101 end102 103 end104end