Socket
Socket
Sign inDemoInstall

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

3

package.json
{
"name": "middy",
"version": "0.7.1",
"version": "0.7.2",
"description": "The simple (but cool 😎) middleware engine for AWS lambda in Node.js",

@@ -63,2 +63,3 @@ "main": "src/index.js",

"ajv-keywords": "^3.0.0",
"content-type": "^1.0.4",
"http-errors": "^1.6.2",

@@ -65,0 +66,0 @@ "qs": "^6.5.0",

const createError = require('http-errors')
const contentType = require('content-type')
module.exports = () => ({
before: (handler, next) => {
if (handler.event.headers && handler.event.headers['Content-Type'] === 'application/json') {
try {
handler.event.body = JSON.parse(handler.event.body)
} catch (err) {
throw new createError.UnprocessableEntity('Content type defined as JSON but an invalid JSON was provided')
if (handler.event.headers && handler.event.headers['Content-Type']) {
const { type } = contentType.parse(handler.event.headers['Content-Type'])
if (type === 'application/json') {
try {
handler.event.body = JSON.parse(handler.event.body)
} catch (err) {
throw new createError.UnprocessableEntity('Content type defined as JSON but an invalid JSON was provided')
}
}

@@ -11,0 +15,0 @@ }

@@ -0,1 +1,3 @@

const contentType = require('content-type')
const defaults = {

@@ -11,7 +13,12 @@ extended: false

if (handler.event.headers && handler.event.headers['Content-Type'].indexOf('application/x-www-form-urlencoded') === 0) {
handler.event.body = parserFn(handler.event.body)
if (handler.event.headers && handler.event.headers['Content-Type']) {
const { type } = contentType.parse(handler.event.headers['Content-Type'])
if (type === 'application/x-www-form-urlencoded') {
handler.event.body = parserFn(handler.event.body)
}
}
next()
}
})
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