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
Option to attach to body as key-value pairs #348
Conversation
This makes sense to me. |
It looks kind of confusing that valuesOnly still creates key value pairs. Also is the for loop fast? I would do classical with Object.keys. |
I agree, the option name could be better. Any suggestions? Maybe something like
Will do!
Good catch. Is it adequate to use |
On second look, I don't think additional changes are need for this. The request body is using the same set of keys, and only re-assigning the value. Prototype pollution should already be handled for these keys by the time this path is reached, right? |
I think it is now good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is required.
Documentation added for the new |
Co-authored-by: Igor Savin <iselwin@gmail.com>
Thank you! |
Adds an option
attachFieldsToBody: 'valueOnly'
. When this is option is enabled, the field values are attached to the body directly, similar to what is described in the readme:This would be a convenient feature to include so that json-schemas can be shared more easily between the content types
application/json
,application/x-www-form-urlencoded
, andmultipart/form-data
.Without this capability, this needs to be performed in awkward route handler transforms, e.g.:
Please let me know if the the convention
attachFieldsToBody: 'valueOnly'
should be changed to something else.Also, currently files are converted to a string via
.toBuffer().toString()
. It's possible to use theonFile
handler to customize the file buffer decoding, which is performed in one of the new tests.Let me know if this feature make sense, and I'm happy to add info to the docs/readme.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct