You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
831 B
48 lines
831 B
4 years ago
|
'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)
|
||
|
}
|
||
|
}
|