Skip to content
Myr

Merge branch 'sendfile' into connect

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 eaee395, f9f2fac · Browse files · 3 files+47 added−1 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+47 added−1 removed

  • tests:+22 added−0 removed
  • other:+25 added−1 removed

3 files+47 added−1 removed

modified:lib/express/response.js+25 added-1 removed
7 unmodified lines
8/**9 * Module dependencies.10 */1112var fs = require('fs'),12var http = require('http'),13 http = require('http'),14 path = require('path'),15 utils = require('connect/utils'),16 mime = require('connect/utils').mime,17 Buffer = require('buffer').Buffer;
70 unmodified lines
88 this.end(body);89};9091/**92 * Transfer the given `file`. Automatically sets the _Content-Type_93 * response header, and responds with 404 / 500 appropriately.94 *95 * @param {String} file96 * @api public97 */9899http.ServerResponse.prototype.sendfile = function(file){100 var self = this;101 fs.readFile(file, function(err, buf){102 if (err) {103 self.send(err.errno === process.ENOENT104 ? 404105 : 500);106 } else {107 self.contentType(file);108 self.send(buf);109 }110 });111};112113114/**115 * Set _Content-Type_ response header passed through `mime.type()`.116 *117 * Examples:118 *
105 unmodified lines
added:test/fixtures/user.json+1 added
modified:test/response.test.js+21 added