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

lws-request-monitor

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lws-request-monitor - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

16

index.js
module.exports = MiddlewareBase => class RequestMonitor extends MiddlewareBase {
middleware () {
return async (ctx, next) => {
const util = require('util')
/* first, inspect the request */
const reqInfo = {

@@ -11,5 +14,15 @@ socketId: ctx.req.socket.id,

}
if (ctx.request.body) reqInfo.data = ctx.request.body
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')
}
}
this.emit('verbose', 'server.request', reqInfo)
/* next, inspect the response */
await next()

@@ -26,3 +39,2 @@ const resInfo = {

const stream = require('stream')
const util = require('util')
if (resInfo.data instanceof stream.Readable) {

@@ -29,0 +41,0 @@ resInfo.data[util.inspect.custom] = function (depth, options) {

5

package.json
{
"name": "lws-request-monitor",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "0.1.0",
"version": "0.1.1",
"description": "Verbose request logging middleware for lws",

@@ -19,3 +19,6 @@ "repository": "https://github.com/lwsjs/request-monitor.git",

"test-runner-counter": "^0.1.1"
},
"dependencies": {
"byte-size": "^4.0.1"
}
}
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