Skip to content
Myr

Added callback support for res.sendfile()

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 2844b1a · Browse files · 2 files+12 added−7 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+12 added−7 removed

  • tests:+5 added−2 removed
  • other:+7 added−5 removed

2 files+12 added−7 removed

modified:lib/express/response.js+7 added-5 removed
87 unmodified lines
88 this.end(body);89};9091/**92 * Transfer the given `file`. Automatically sets the _Content-Type_92 * Transfer the file at the given `path`. Automatically sets the _Content-Type_93 * response header, and responds with 404 / 500 appropriately.94 *95 * @param {String} file95 * @param {String} path96 * @param {Function} fn97 * @api public98 */9999http.ServerResponse.prototype.sendfile = function(file){100http.ServerResponse.prototype.sendfile = function(path, fn){101 var self = this;101 fs.readFile(file, function(err, buf){102 fs.readFile(path, function(err, buf){103 if (err) {104 self.send(err.errno === process.ENOENT105 ? 404106 : 500);107 } else {107 self.contentType(file);108 self.contentType(path);109 self.send(buf);110 fn && fn(null, path);111 }112 });113};114
123 unmodified lines
modified:test/response.test.js+5 added-2 removed
173 unmodified lines
174 'test #sendfile()': function(assert){175 var app = express.createServer();176 177 app.get('/*', function(req, res){178 var file = req.params[0];179 res.sendfile(__dirname + '/fixtures/' + file);178 var file = req.params[0],179 filePath = __dirname + '/fixtures/' + file;180 res.sendfile(filePath, function(err, path){181 assert.equal(path, filePath);182 });183 });184 185 assert.response(app,186 { url: '/user.json' },
38 unmodified lines