Comparing version 0.7.1 to 0.7.2
{ | ||
"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() | ||
} | ||
}) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
75272
1557
4
7
+ Addedcontent-type@^1.0.4
+ Addedcontent-type@1.0.5(transitive)