Merge branch 'download' of git://github.com/aheckmann/express into integration
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents 33d004f, bd6f24f · Browse files · 4 files·+42 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+42 added−15 removed
- tests:+26 added−0 removed
- other:+16 added−15 removed
Provenance
- Commit
09bb10c- Tree
f0d1361- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
33d004f- Parent 2
bd6f24f
4 files changed+42 added−15 removed
modified:lib/express/plugins/static.js+13 added
109 unmodified linesExpand all110111112113114115116117118119120121122123124125126127128129130131109 unmodified linesExpand all
sendfile: function(path) { (new exports.File(path)).sendTo(this) return this }, /** * Transfer static _file_ as an attachment. * The basename of _file_ is used as the attachment filename. * * @param {string} file * @return {Request} * @api public */
download: function(file) { return this.attachment(path.basename(file)).sendfile(file) } }) } }})modified:lib/express/request.js-13 removed
262 unmodified lines263 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} path76 unmodified linesmodified:spec/spec.plugins.static.js+26 added
72 unmodified lines73 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 end104 endmodified:Readme.md+3 added-2 removed
25 unmodified lines26 * Full test coverage27 * Logger plugin with several formats28 * Upload size restrictions29 * Extremely readable specs30+ * Cookie support31 32 ## Installation33 34 Install the [Kiwi package manager for nodejs](http://github.com/visionmedia/kiwi)9 unmodified lines44 45 ## Performance46 47 Extensive performance enhancements have not yet been made,47- since we are focusing on the framework it-self at the moment. 48+ since we are focusing on the framework itself at the moment. 49 50 However if you are interested view the premature [benchmarks for Express framework](http://vision-media.ca/resources/nodejs/express-nodejs-web-development-framework-performance).51 52 ## Examples33 unmodified lines86 $ node spec/node.js routing87 ...88 89 The latest release of Express is compatible with node --version:89- v0.1.3390+ v0.1.9091 92 EDGE Express we do our best to keep up to date with node's EDGE93 94 ## More Information36 unmodified lines