nestjs
nestjs copied to clipboard
Allow to specify `limit` for `raw` parser
When using the RawBodyMiddleware middleware, it doesn't allow to provide a configurable limit parameter.
@Injectable()
export class RawBodyMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: () => any) {
raw({ type: '*/*' })(req, res, next);
}
}
In case of large payloads, it could cause raw-body library to throw a PayloadTooLarge exception.
function readStream (stream, encoding, length, limit, callback) {
var complete = false
var sync = true
// check the length and limit options.
// note: we intentionally leave the stream paused,
// so users should handle the stream themselves.
if (limit !== null && length !== null && length > limit) {
return done(createError(413, 'request entity too large', {
expected: length,
length: length,
limit: limit,
type: 'entity.too.large'
}))
}
Is there any way to work around this restriction?
@gastonelhordoy I believe this could be tweaked and possibly allow developers to inject that and our module infer through DI. Do you think you could potentially push this feature? I would be happy to review and push but currently i do not have enough time to develop such feature