Skip to content
Myr

refactored `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 0932bde · Browse files · 1 file+18 added−6 removed
This commit

State

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

Diff stats

1 file+18 added−6 removed

  • other:+18 added−6 removed

1 file+18 added−6 removed

modified:lib/response.js+18 added-6 removed
141 unmodified lines
142 return this;143};144145/**146 * Transfer the file at the given `path`. Automatically sets 147 * the _Content-Type_ response header field. `next()` is called148 * when `path` is a directory, or when an error occurs.146 * Transfer the file at the given `path`.147 * 148 * Automatically sets the _Content-Type_ response header field.149 * The callback `fn(err)` is invoked when the transfer is complete150 * or when an error occurs. Be sure to check `res.headerSent`151 * if you wish to attempt responding, as the header and some data152 * may have already been transferred.153 *154 * Options:155 *156 * - `maxAge` defaulting to 0
5 unmodified lines
162 * @api public163 */164165res.sendfile = function(path, options, fn){162 var next = this.req.next;163 options = options || {};166 var self = this167 , next = this.req.next168 , options = options || {};169170 // support function as second arg171 if ('function' == typeof options) {172 fn = options;173 options = {};174 }175176 // callback177 options.callback = function(err){178 // TODO: remove when node adds this179 self.headerSent = !! self._header;180 fn && fn(err);181 };182183 // transfer184 options.path = encodeURIComponent(path);172 options.callback = fn;185 send(this.req, this, next, options);186};187188/**
260 unmodified lines