Skip to content
Myr

Started Request#stream() based of Aarons work on Static#streamfile()

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

authored by visionmedia · committed by visionmedia · parent 28df150 · Browse files · 3 files+77 added−39 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+77 added−39 removed

  • other:+77 added−39 removed

3 files+77 added−39 removed

modified:lib/express/plugins/content-length.js+4 added-3 removed
modified:lib/express/plugins/static.js+31 added-36 removed
modified:lib/express/request.js+42 added
199 unmodified lines
200 }, true)201 },202 203 /**204 * Transfer the given _stream_.205 *206 * @param {Stream} stream207 * @return {Request}208 * @api public209 */210 211 stream: function(stream, callback) {212 var self = this,213 first = true214 stream215 .addListener('error', function(err){216 if (first)217 return 'errno' in err && err.errno === 2218 ? self.notFound()219 : self.error(err)220 // TODO: err wtf ? bad file descriptor apparently...221 self.response.end()222 })223 .addListener('data', function(data){224 if (first) {225 self.status(200)226 first = false227 self.contentType(stream.path)228 self.response.writeHeader(self.response.status, self.response.headers)229 self.response.write(data, 'binary')230 } else231 self.response.write(data, 'binary')232 })233 .addListener('end', function(){234 self.response.end()235 self.trigger('response', function(err){236 if (err) {237 stream.destroy()238 if (callback !== undefined) callback(err)239 else self.error(err)240 }241 }, true)242 })243 },244 245 /**246 * Pass control to the next matching route, or247 * the given _path_.248 *249 * NOTE: _path_ may be the request pathname only,
142 unmodified lines