-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] incorrect behavior of RawBodyParams
#1819
Comments
Hello @derevnjuk perfect issue description ;)
I’m not sure how to fix that correctly. If you have a solution or an idea, let’s go ;) See you |
Now bodyParser is embed directly in the core and can be configured. Closes: #1819
Hello @derevnjuk it doesn’t fix issue if the server add a body parser during the $beforeRoutesInit. But if the body parser is removed, it works as expected. There is no better option ^^. The pr is almost ready. I need to update the documention. see you |
Now bodyParser is embed directly in the core and can be configured. Closes: #1819
🎉 This issue has been resolved in version 6.111.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 7.0.0-beta.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Information
6.x
platform-express
In implementing HTTP signature verification (e.g. Stripe or GitHub), it might be useful to get the raw body. Currently, it is almost impossible to use
RawBodyParams
since it has limitations by content type and length.RawBodyParams
returns a string instead of an instance of BufferIn docs stated that
RawBodyParams
returns the value fromrequest.body
as aBuffer
(see https://api-docs.tsed.io/api/platform/platform-params/types/decorators/RawBodyParams.html).But it returns a string since
chunk
is implicitly casting to string due to using a string concatenation inrawBodyMiddleware
:Moreover,
rawBodyMiddleware
doesn't care about a charset at the same time.Expecting
data
events to be synchronouslyThe middleware may not run well until the reading is finished. That means,
rawBody
may be undefined in some cases when consuming data takes more time than usual:To fix that, you have to rewrite the middleware as follows:
There is also another problem since the stream is switched in flowing mode by subscribing to the
data
event, it may lead to some race between different body parsers. For instance, you can use$afterInit
to registerexpress.json()
middleware that consumes all data from the request preventing catchingrawBody
:Since the readable stream is ended, the previous example will be stuck, and the current implementation will just set an empty string to
req.rawBody
.Acceptance criteria
rawBody
independently of using other body parsersRawBodyParams
should return a Buffer instead of a string by defaultRawBodyParams
to obtain a string according to charsetThe text was updated successfully, but these errors were encountered: