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

@ -89,7 +89,7 @@ function finalhandler (req, res, options) {
var status
// ignore 404 on in-flight response
if (!err && res._header) {
if (!err && headersSent(res)) {
debug('cannot 404 after headers sent')
return
}
@ -99,14 +99,12 @@ function finalhandler (req, res, options) {
// respect status code from error
status = getErrorStatusCode(err)
// respect headers from error
if (status !== undefined) {
headers = getErrorHeaders(err)
}
// fallback to status code on response
if (status === undefined) {
// fallback to status code on response
status = getResponseStatusCode(res)
} else {
// respect headers from error
headers = getErrorHeaders(err)
}
// get error message
@ -114,7 +112,7 @@ function finalhandler (req, res, options) {
} else {
// not found
status = 404
msg = 'Cannot ' + req.method + ' ' + encodeUrl(parseUrl.original(req).pathname)
msg = 'Cannot ' + req.method + ' ' + encodeUrl(getResourceName(req))
}
debug('default %s', status)
@ -125,7 +123,7 @@ function finalhandler (req, res, options) {
}
// cannot actually respond
if (res._header) {
if (headersSent(res)) {
debug('cannot %d after headers sent', status)
req.socket.destroy()
return
@ -208,6 +206,25 @@ function getErrorStatusCode (err) {
return undefined
}
/**
* Get resource name for the request.
*
* This is typically just the original pathname of the request
* but will fallback to "resource" is that cannot be determined.
*
* @param {IncomingMessage} req
* @return {string}
* @private
*/
function getResourceName (req) {
try {
return parseUrl.original(req).pathname
} catch (e) {
return 'resource'
}
}
/**
* Get status code from response.
*
@ -227,6 +244,20 @@ function getResponseStatusCode (res) {
return status
}
/**
* Determine if the response headers have been sent.
*
* @param {object} res
* @returns {boolean}
* @private
*/
function headersSent (res) {
return typeof res.headersSent !== 'boolean'
? Boolean(res._header)
: res.headersSent
}
/**
* Send response.
*