refactor: move common request validation to read function #600
+94
−176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR moves the common request validation logic, previously duplicated across all parsers, into the
read
function. This improves maintainability, reduces package size, and brings us closer to our goal of a generic body parser (see #22).It also adds support for the
defaultCharset
option innormalizeOptions()
. This option was already supported in theqs
andtext
parsers, and I’ve now added support in thejson
parser as well. While we’ll likely want to validate these options more thoroughly in a future major release, the current approach should suffice for now.There’s not much left before we can move the full middleware creation logic into its own function, but I wanted to keep this PR focused and manageable. Small steps toward our goals.