fastify-raw-body
Advanced tools
Comparing version 4.1.0 to 4.1.1
{ | ||
"name": "fastify-raw-body", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Request raw body", | ||
@@ -37,3 +37,3 @@ "main": "plugin.js", | ||
"tap": "^16.2.0", | ||
"tsd": "^0.23.0" | ||
"tsd": "^0.24.1" | ||
}, | ||
@@ -40,0 +40,0 @@ "dependencies": { |
@@ -59,5 +59,7 @@ 'use strict' | ||
function preparsingRawBody (request, reply, payload, done) { | ||
const applyLimit = request.context._parserOptions.limit ?? fastify.initialConfig.bodyLimit | ||
getRawBody(runFirst ? request.raw : payload, { | ||
length: null, // avoid content lenght check: fastify will do it | ||
limit: fastify.initialConfig.bodyLimit, // limit to avoid memory leak or DoS | ||
limit: applyLimit, // limit to avoid memory leak or DoS | ||
encoding | ||
@@ -69,3 +71,7 @@ }, function (err, string) { | ||
* so the request object will not have any | ||
* `body` parsed | ||
* `body` parsed. | ||
* | ||
* The preparsingRawBody decorates the request | ||
* meanwhile the `payload` is processed by | ||
* the fastify server. | ||
*/ | ||
@@ -89,6 +95,7 @@ return | ||
try { | ||
var json = secureJson.parse(body.toString('utf8'), { | ||
const json = secureJson.parse(body.toString('utf8'), { | ||
protoAction: fastify.initialConfig.onProtoPoisoning, | ||
constructorAction: fastify.initialConfig.onConstructorPoisoning | ||
}) | ||
done(null, json) | ||
} catch (err) { | ||
@@ -98,3 +105,2 @@ err.statusCode = 400 | ||
} | ||
done(null, json) | ||
} | ||
@@ -101,0 +107,0 @@ } |
@@ -418,2 +418,8 @@ 'use strict' | ||
t.equal(res.statusCode, 413) | ||
t.same(res.json(), { | ||
statusCode: 413, | ||
code: 'FST_ERR_CTP_BODY_TOO_LARGE', | ||
error: 'Payload Too Large', | ||
message: 'Request body is too large' | ||
}) | ||
}) | ||
@@ -420,0 +426,0 @@ |
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
24403
8
682