Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino-http

Package Overview
Dependencies
Maintainers
4
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-http - npm Package Compare versions

Comparing version 2.6.2 to 3.0.0

116

logger.js

@@ -15,4 +15,4 @@ 'use strict'

opts.serializers = opts.serializers || {}
opts.serializers.req = opts.serializers.req || asReqValue
opts.serializers.res = opts.serializers.res || pino.stdSerializers.res
opts.serializers.req = wrapReqSerializer(opts.serializers.req || asReqValue)
opts.serializers.res = wrapResSerializer(opts.serializers.res || asResValue)
opts.serializers.err = opts.serializers.err || pino.stdSerializers.err

@@ -68,14 +68,110 @@

var rawSymbol = Symbol.for('pino-raw-ref')
var pinoReqProto = Object.create({}, {
id: {
enumerable: true,
writable: true,
value: ''
},
method: {
enumerable: true,
writable: true,
value: ''
},
url: {
enumerable: true,
writable: true,
value: ''
},
headers: {
enumerable: true,
writable: true,
value: {}
},
remoteAddress: {
enumerable: true,
writable: true,
value: ''
},
remotePort: {
enumerable: true,
writable: true,
value: ''
},
raw: {
enumerable: false,
get: function () {
return this[rawSymbol]
},
set: function (val) {
this[rawSymbol] = val
}
}
})
Object.defineProperty(pinoReqProto, rawSymbol, {
writable: true,
value: {}
})
function wrapReqSerializer (serializer) {
if (serializer === asReqValue) return asReqValue
return function wrappedReqSerializer (req) {
return serializer(asReqValue(req))
}
}
function asReqValue (req) {
var connection = req.connection
return {
id: req.id,
method: req.method,
url: req.url,
headers: req.headers,
remoteAddress: connection && connection.remoteAddress,
remotePort: connection && connection.remotePort
const _req = Object.create(pinoReqProto)
_req.id = req.id
_req.method = req.method
_req.url = req.url
_req.headers = req.headers
_req.remoteAddress = connection && connection.remoteAddress
_req.remotePort = connection && connection.remotePort
_req.raw = req
return _req
}
var pinoResProto = Object.create({}, {
statusCode: {
enumerable: true,
writable: true,
value: 0
},
header: {
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 asResValue (res) {
const _res = Object.create(pinoResProto)
_res.statusCode = res.statusCode
_res.header = res._header
_res.raw = res
return _res
}
function wrapResSerializer (serializer) {
if (serializer === asResValue) return asResValue
return function wrappedResSerializer (res) {
return serializer(asResValue(res))
}
}
function wrapChild (opts, stream) {

@@ -111,4 +207,4 @@ var prevLogger = opts.logger

req: asReqValue,
res: pino.stdSerializers.res
res: asResValue
}
module.exports.startTime = startTime

4

package.json
{
"name": "pino-http",
"version": "2.6.2",
"version": "3.0.0",
"description": "High-speed HTTP logger for Node.js",
"main": "logger.js",
"dependencies": {
"pino": "^4.0.2"
"pino": "^4.10.2"
},

@@ -9,0 +9,0 @@ "devDependencies": {

@@ -306,1 +306,112 @@ 'use strict'

})
// https://github.com/pinojs/pino-http/issues/42
test('does not return excessively long object', function (t) {
var dest = split(JSON.parse)
var logger = pinoHttp({
logger: pino(dest),
serializers: {
req: function (req) {
delete req.connection
return req
}
}
})
t.plan(1)
var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
const port = server.address().port
http.get(`http://127.0.0.1:${port}`, () => {})
})
function handler (req, res) {
logger(req, res)
res.end()
}
dest.on('data', function (obj) {
t.is(Object.keys(obj.req).length, 6)
})
})
test('req.raw is available to custom serializers', function (t) {
t.plan(2)
var dest = split(JSON.parse)
var logger = pinoHttp({
logger: pino(dest),
serializers: {
req: function (req) {
t.ok(req.raw)
t.ok(req.raw.connection)
return req
}
}
})
var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
const port = server.address().port
http.get(`http://127.0.0.1:${port}`, () => {})
})
function handler (req, res) {
logger(req, res)
res.end()
}
})
test('res.raw is available to custom serializers', function (t) {
t.plan(2)
var dest = split(JSON.parse)
var logger = pinoHttp({
logger: pino(dest),
serializers: {
res: function (res) {
t.ok(res.raw)
t.ok(res.raw.statusCode)
return res
}
}
})
var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
const port = server.address().port
http.get(`http://127.0.0.1:${port}`, () => {})
})
function handler (req, res) {
logger(req, res)
res.end()
}
})
test('res.raw is not enumerable', function (t) {
t.plan(1)
var dest = split(JSON.parse)
var logger = pinoHttp({
logger: pino(dest),
serializers: {
res: function (res) {
t.is(res.propertyIsEnumerable('raw'), false)
return res
}
}
})
var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
const port = server.address().port
http.get(`http://127.0.0.1:${port}`, () => {})
})
function handler (req, res) {
logger(req, res)
res.end()
}
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc