Stream request body with "request.request.pipe(...)" #3381
Replies: 3 comments
-
Ok, after looking at this file (bodyparser module): https://github.com/adonisjs/bodyparser/blob/develop/src/BodyParser/index.ts I have seen that I can disable it at all emptying whitelistedMethods: At the const bodyParserConfig: BodyParserConfig = {
/*
|--------------------------------------------------------------------------
| White listed methods
|--------------------------------------------------------------------------
|
| HTTP methods for which body parsing must be performed. It is a good practice
| to avoid body parsing for `GET` requests.
|
*/
// whitelistedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
whitelistedMethods: [], You can disable processing request at multipart, raw, json... individually. Per route only available at multipart, it will be nice to have it not only in multipart but in json and raw too. |
Beta Was this translation helpful? Give feedback.
-
Or disable the middleware at all at Server.middleware.register([
// () => import('@ioc:Adonis/Core/BodyParser'),
]) |
Beta Was this translation helpful? Give feedback.
-
Yes disable the bodyparser middleware and self handle the request stream. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Descripcion
It's possible to disable body parser for a specific route or for all the project and stream the request body in the controller?
Example
Objective
We are using AdonisJS 5 as a Reserve proxy with some logic, we want to accept big requests but not to load them into memory, so we have disabled JSON parser, but request.raw() holds all the string request in memory.
We want to stream the request to Google Storage and to the Backend Server and we need to do it after entering the controller, where the logic to what to do with the request is done.
In another small frameworks like Express it's possible:
https://stackoverflow.com/questions/61660783/nodejs-expressjs-how-to-stream-request-body-without-buffering
I imagine that the body parser module reads the request content and pipe can't be consumed anymore.
Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions