Firebase Update

This commit is contained in:
Lukas Nowy
2018-12-22 23:30:39 +01:00
parent befb44764d
commit acffe619b3
11523 changed files with 1614327 additions and 930246 deletions

View File

@ -19,7 +19,6 @@ var destroy = require('destroy')
var encodeUrl = require('encodeurl')
var escapeHtml = require('escape-html')
var etag = require('etag')
var EventEmitter = require('events').EventEmitter
var fresh = require('fresh')
var fs = require('fs')
var mime = require('mime')
@ -71,14 +70,6 @@ var UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/
module.exports = send
module.exports.mime = mime
/**
* Shim EventEmitter.listenerCount for node.js < 0.10
*/
/* istanbul ignore next */
var listenerCount = EventEmitter.listenerCount ||
function (emitter, type) { return emitter.listeners(type).length }
/**
* Return a `SendStream` for `req` and `path`.
*
@ -146,6 +137,10 @@ function SendStream (req, path, options) {
? normalizeList(opts.extensions, 'extensions option')
: []
this._immutable = opts.immutable !== undefined
? Boolean(opts.immutable)
: false
this._index = opts.index !== undefined
? normalizeList(opts.index, 'index option')
: ['index.html']
@ -271,7 +266,7 @@ SendStream.prototype.maxage = deprecate.function(function maxage (maxAge) {
SendStream.prototype.error = function error (status, err) {
// emit if listeners instead of responding
if (listenerCount(this, 'error') !== 0) {
if (hasListeners(this, 'error')) {
return this.emit('error', createError(status, err, {
expose: false
}))
@ -480,7 +475,7 @@ SendStream.prototype.isRangeFresh = function isRangeFresh () {
SendStream.prototype.redirect = function redirect (path) {
var res = this.res
if (listenerCount(this, 'directory') !== 0) {
if (hasListeners(this, 'directory')) {
this.emit('directory', res, path)
return
}
@ -534,19 +529,24 @@ SendStream.prototype.pipe = function pipe (res) {
var parts
if (root !== null) {
// normalize
if (path) {
path = normalize('.' + sep + path)
}
// malicious path
if (UP_PATH_REGEXP.test(normalize('.' + sep + path))) {
if (UP_PATH_REGEXP.test(path)) {
debug('malicious path "%s"', path)
this.error(403)
return res
}
// explode path parts
parts = path.split(sep)
// join / normalize from optional root dir
path = normalize(join(root, path))
root = normalize(root + sep)
// explode path parts
parts = path.substr(root.length).split(sep)
} else {
// ".." is malicious without "root"
if (UP_PATH_REGEXP.test(path)) {
@ -870,6 +870,11 @@ SendStream.prototype.setHeader = function setHeader (path, stat) {
if (this._cacheControl && !res.getHeader('Cache-Control')) {
var cacheControl = 'public, max-age=' + Math.floor(this._maxage / 1000)
if (this._immutable) {
cacheControl += ', immutable'
}
debug('cache-control %s', cacheControl)
res.setHeader('Cache-Control', cacheControl)
}
@ -928,7 +933,8 @@ function collapseLeadingSlashes (str) {
function containsDotFile (parts) {
for (var i = 0; i < parts.length; i++) {
if (parts[i][0] === '.') {
var part = parts[i]
if (part.length > 1 && part[0] === '.') {
return true
}
}
@ -965,7 +971,8 @@ function createHtmlDocument (title, body) {
'</head>\n' +
'<body>\n' +
'<pre>' + body + '</pre>\n' +
'</body>\n'
'</body>\n' +
'</html>\n'
}
/**
@ -1000,6 +1007,26 @@ function getHeaderNames (res) {
: res.getHeaderNames()
}
/**
* Determine if emitter has listeners of a given type.
*
* The way to do this check is done three different ways in Node.js >= 0.8
* so this consolidates them into a minimal set using instance methods.
*
* @param {EventEmitter} emitter
* @param {string} type
* @returns {boolean}
* @private
*/
function hasListeners (emitter, type) {
var count = typeof emitter.listenerCount !== 'function'
? emitter.listeners(type).length
: emitter.listenerCount(type)
return count > 0
}
/**
* Determine if the response headers have been sent.
*