Skip to content

Commit

Permalink
Merge remote branch 'aheckmann/staticbuffersize'
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 10, 2010
2 parents 497a284 + 32cd51d commit 66c6152
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/express/plugins/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ exports.Static = Plugin.extend({
if (options instanceof Function)
callback = options,
options = {}
else
options = options || {}
if (path.indexOf('..') !== -1)
Error.raise('InvalidPathError', "`" + path + "' is not a valid path")
fs.stat(path, function(err, stat){
Expand All @@ -68,7 +70,16 @@ exports.Static = Plugin.extend({
return self.respond(304, null)
self.header('Content-Length', stat.size)
self.header('ETag', etag)
self.stream(fs.createReadStream(path, options))
options.bufferSize = options.bufferSize
|| set('static buffer size')
|| 65536
if (stat.size > options.bufferSize)
return self.stream(fs.createReadStream(path, options))
fs.readFile(path, function(err, content){
if (err) return self.error(err, callback)
self.contentType(path)
self.respond(200, content)
})
})
return this
},
Expand Down

0 comments on commit 66c6152

Please sign in to comment.