action-debian-package/node_modules/pino-std-serializers/lib/res.js
Dawid Dziurla 9308795b8b
update
2020-03-26 15:37:35 +01:00

48 lines
831 B
JavaScript

'use strict'
module.exports = {
mapHttpResponse,
resSerializer
}
var rawSymbol = Symbol('pino-raw-res-ref')
var pinoResProto = Object.create({}, {
statusCode: {
enumerable: true,
writable: true,
value: 0
},
headers: {
enumerable: true,
writable: true,
value: ''
},
raw: {
enumerable: false,
get: function () {
return this[rawSymbol]
},
set: function (val) {
this[rawSymbol] = val
}
}
})
Object.defineProperty(pinoResProto, rawSymbol, {
writable: true,
value: {}
})
function resSerializer (res) {
const _res = Object.create(pinoResProto)
_res.statusCode = res.statusCode
_res.headers = res.getHeaders ? res.getHeaders() : res._headers
_res.raw = res
return _res
}
function mapHttpResponse (res) {
return {
res: resSerializer(res)
}
}