-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: keep original headers after validation #26
Conversation
🎉 This PR is included in version 5.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
-
I was expecting that we'll need to pass
convert: false
togetValidationResult
, so Joi would not mutate the object that we're passing to it. Maybe you checked with tests that it does not mutate anything? (I usually check so by doing_deepFreeze(obj)
, which would throw if it's attempted to be mutated) -
I'm questioning the need for
keepOriginal
option, and its default, and if same default is applicable to the body/query/params vs headers.
Why?
a. body/query/params didn't have an issue with "mutation by default", so, new option is not strictly important.
b. the headers
mutation you now default to true
, right? (if I'm not mistaken) I find it dangerous, as "default should be safe" (non-mutating)
So, I thought maybe we just hard-code the behavior that headers
validation is always non-mutating, while everything else is always mutating?
Or, if you don't like it, we may do "different default for different properties" (which I don't like much, as it'll less clear/obvious to the consumer)
@@ -16,6 +16,11 @@ export interface ReqValidationOptions<ERR extends Error> { | |||
* If true - `genericErrorHandler` will report it to errorReporter (aka Sentry). | |||
*/ | |||
report?: boolean | ((err: ERR) => boolean) | |||
|
|||
/** |
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.
p3: I have a habit to explicitly document what is a default value of every option, e.g here I'd write like Defaults to false, which means it would **convert**/mutate the original value. Set to true to force non-mutating behavior
.
Your description is good, but I like the emphasis on "what is default, and what happens when you flip the default".
The issue is not with conversion. Having =>
I am not sure I understand or I think you misunderstand the current flow:
👍 You are right. |
In this PR, I made it so that we do not replace the
req.headers
after validation.This feature can be controlled by the
opt.keepOriginal
flag.We decided to do so, because we want to validate only a subset of headers in NCB3, and replacing them on the Request object would break many parts of the application, meanwhile we do not want to validate every header at a single location.