Skip to content
Myr

Fixed res.download() bug; when an error occurs remove Content-Disposition

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

Previously if you tried to show a 404 page (or similar) on a failed res.download(), the browser would still prompt for download

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 20af737 · Browse files · 2 files+11 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

2 files+11 added−0 removed

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

2 files+11 added−0 removed

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