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
Extend content type parser #3210
Conversation
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.
good work! Just a nit
lib/contentTypeParser.js
Outdated
} | ||
|
||
if (Array.isArray(contentType)) { | ||
contentType.forEach((type) => this[kContentTypeParser].remove(type)) |
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.
Can you please use a for..of loop?
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 will change it later! I used forEach
because it is also used here.
docs/ContentTypeParser.md
Outdated
fastiy.removeContentTypeParser(['application/json', 'text/plain']) | ||
``` | ||
|
||
#### resetContentTypeParsers |
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 think the name can be improved. Reset
sounds to me reset to some point which mostly reset to default value.
It would be better if it called removeAll
.
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.
Agreed!
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.
Makes sense to me! I will update the name
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.
lgtm
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.
Good one!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
Closes #2994. This PR adds the 2 methods
resetContentTypeParsers
andremoveContentTypeParser
to the Fastify instance. WithresetContentTypeParsers
all current content type parser can be deleted (including the both built-in content type parsers). This is especially useful if you want to implement a catch-all content type parser that should be called even if the content type isapplication/json
. WithremoveContentTypeParser
a single or an array of content type parsers can be removed. Both APIs support encapsulation.