lws-request-monitor
Advanced tools
Comparing version 0.1.1 to 0.1.2
32
index.js
@@ -14,10 +14,8 @@ module.exports = MiddlewareBase => class RequestMonitor extends MiddlewareBase { | ||
} | ||
if (ctx.request.rawBody) reqInfo.data = ctx.request.rawBody | ||
const incomingBuffer = ctx.req._readableState.buffer | ||
if (!reqInfo.data && incomingBuffer.head && incomingBuffer.head.data.length) { | ||
reqInfo.data = '__INCOMING__' | ||
reqInfo.data[util.inspect.custom] = function (depth, options) { | ||
const byteSize = require('byte-size') | ||
const size = byteSize(incomingBuffer.head.data.length) | ||
return options.stylize(`[ incoming data (${size} so far) ]`, 'special') | ||
if (ctx.request.rawBody) { | ||
reqInfo.body = ctx.request.body | ||
} else { | ||
const incomingBuffer = ctx.req._readableState.buffer | ||
if (incomingBuffer.head && incomingBuffer.head.data.length) { | ||
reqInfo.bodyHead = incomingBuffer.head.data.toString('utf8', 0, 1000) | ||
} | ||
@@ -36,8 +34,18 @@ } | ||
if (headers) resInfo.headers = headers | ||
if (ctx.body) resInfo.data = ctx.body | ||
if (ctx.body) resInfo.body = ctx.body | ||
const stream = require('stream') | ||
if (resInfo.data instanceof stream.Readable) { | ||
resInfo.data[util.inspect.custom] = function (depth, options) { | ||
return options.stylize(`[ Readable Stream: ${resInfo.data.path} ]`, 'special') | ||
if (resInfo.body instanceof stream.Readable) { | ||
if (/text\/event-stream/.test(ctx.response.type)) { | ||
resInfo.body[util.inspect.custom] = function (depth, options) { | ||
return options.stylize('[ SSE event-stream ]', 'special') | ||
} | ||
} else if (ctx.body.path) { | ||
resInfo.body[util.inspect.custom] = function (depth, options) { | ||
return options.stylize(`[ ReadStream: ${ctx.body.path} ]`, 'special') | ||
} | ||
} else { | ||
resInfo.body[util.inspect.custom] = function (depth, options) { | ||
return options.stylize(`[ Readable Stream ]`, 'special') | ||
} | ||
} | ||
@@ -44,0 +52,0 @@ } |
{ | ||
"name": "lws-request-monitor", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Verbose request logging middleware for lws", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/lwsjs/request-monitor.git", |
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
21694
71