Skip to content
Myr

Merge branch 'download-example'

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 · parents a33fb0c, bbe65a8 · Browse files · 4 files+44 added−0 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+44 added−0 removed

  • tests:+10 added−0 removed
  • other:+34 added−0 removed

4 files+44 added−0 removed

added:examples/downloads/files/amazing.txt+1 added
1wow supes cool are you glad you downloaded this?
added:examples/downloads/app.js+32 added
modified:lib/express/response.js+1 added
128 unmodified lines
129http.ServerResponse.prototype.sendfile = function(path, fn){130 var self = this;131 fs.readFile(path, function(err, buf){132 if (err) {133 delete self.headers['Content-Disposition'];134 if (fn) {135 fn(err, path);136 } else {137 self.req.next(err);
182 unmodified lines
modified:test/response.test.js+10 added
222 unmodified lines
223 app.get('/*', function(req, res, next){224 res.download(__dirname + '/fixtures/' + req.params[0]);225 });226 227 app.error(function(err, req, res){228 res.send(404);229 })230 231 assert.response(app,232 { url: '/user.json' },233 { body: '{"name":"tj"}', status: 200, headers: {234 'Content-Type': 'application/json',
5 unmodified lines
240 { body: '{"name":"tj"}', status: 200, headers: {241 'Content-Type': 'application/json',242 'Content-Disposition': 'attachment; filename="account.json"'243 }});244 245 assert.response(app,246 { url: '/missing' },247 function(res){248 assert.equal(null, res.headers['content-disposition']);249 });250 },251 252 'test #cookie()': function(assert){253 var app = express.createServer();
44 unmodified lines