Comparing version 2.2.0 to 2.3.0
@@ -49,2 +49,8 @@ 'use strict' | ||
function onReqAborted () { | ||
var res = this.res | ||
res.statusCode = 408 | ||
onResFinished.call(res, new Error('Aborted')) | ||
} | ||
function loggingMiddleware (req, res, next) { | ||
@@ -54,5 +60,8 @@ req.id = genReqId(req) | ||
res.startTime = Date.now() | ||
if (!req.res) { req.res = res } | ||
res.on('finish', onResFinished) | ||
res.on('error', onResFinished) | ||
// it's possible that browser aborts connection, or http-server because of timeout | ||
req.on('aborted', onReqAborted) | ||
@@ -59,0 +68,0 @@ if (next) { |
{ | ||
"name": "pino-http", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "High-speed HTTP logger for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "logger.js", |
75
test.js
@@ -32,3 +32,3 @@ 'use strict' | ||
var address = server.address() | ||
http.get('http://' + address.address + ':' + address.port) | ||
return http.get('http://' + address.address + ':' + address.port) | ||
} | ||
@@ -261,1 +261,74 @@ | ||
}) | ||
test('react on aborted event from clientside', function (t) { | ||
var dest = split(JSON.parse) | ||
var idToTest | ||
function genReqId (req) { | ||
t.ok(req.url, 'The first argument must be the request parameter') | ||
idToTest = (Date.now() + Math.random()).toString(32) | ||
return idToTest | ||
} | ||
var logger = pinoHttp({ | ||
logger: pino({ | ||
serializers: pino.stdSerializers | ||
}, dest), | ||
genReqId: genReqId | ||
}) | ||
setup(t, logger, function (err, server) { | ||
t.error(err) | ||
var address = server.address() | ||
var request = http.get({ | ||
host: address.address, | ||
port: address.port | ||
}) | ||
// need this in order to prevent unhadled socket handup | ||
request.on('error', function () {}) | ||
setTimeout(function () { | ||
// break the connection from the clientside | ||
request.abort() | ||
}, 100) | ||
}, logger) | ||
dest.on('data', function (line) { | ||
t.equal(line.msg, 'request errored', 'message is set') | ||
t.equal(line.err.message, 'Aborted', 'error message is set') | ||
t.equal(line.res.statusCode, 408, 'statusCode is 408') | ||
t.end() | ||
}) | ||
}) | ||
test('react on aborted event from server', function (t) { | ||
var dest = split(JSON.parse) | ||
var idToTest | ||
function genReqId (req) { | ||
t.ok(req.url, 'The first argument must be the request parameter') | ||
idToTest = (Date.now() + Math.random()).toString(32) | ||
return idToTest | ||
} | ||
var logger = pinoHttp({ | ||
logger: pino({ | ||
serializers: pino.stdSerializers | ||
}, dest), | ||
genReqId: genReqId | ||
}) | ||
setup(t, logger, function (err, server) { | ||
server.timeout = 100 | ||
t.error(err) | ||
var request = doGet(server) | ||
// need this in order to prevent unhadled socket handup | ||
request.on('error', function () {}) | ||
}, logger) | ||
dest.on('data', function (line) { | ||
t.equal(line.msg, 'request errored', 'message is set') | ||
t.equal(line.err.message, 'Aborted', 'error message is set') | ||
t.equal(line.res.statusCode, 408, 'statusCode is 408') | ||
t.end() | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20494
442