generated from netty-contrib/template-multi
-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor multipart decoding implementation and add new API #25
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
Open
yawkat
wants to merge
11
commits into
netty-contrib:main
Choose a base branch
from
yawkat:multipart-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR adds a new lower-level post body parsing API (PostBodyDecoder). Right now the only implementation is the MultipartDecoder because that's the difficult one, but I plan to implement URL decoding too. The new API is purely stream-based and leaves the data management (e.g. writing to disk) to the caller. This makes it more compatible with netty 5 buffers, makes buffer lifecycles easier to understand to avoid buffer leaks, and simplifies the implementation to allow for future optimization. Because multipart is incredibly complex and the old decoder is the result of years of issue reports for compatibility with obscure clients, and I don't have confidence in the existing test coverage, my main focus in this PR has been validating compatibility. To do this, I've ported HttpPostMultipartRequestDecoder to use the new low-level API internally, and created a fuzz test (MultipartComparisonTest) that compares the output with that of the old decoder (HttpPostMultipartRequestDecoderLegacy). This gives me high confidence that there is no feature regression. In this process, I've found a few behaviors of the old decoder that I consider bugs not worth keeping around. Nonetheless, I've decided to keep HttpPostMultipartRequestDecoder behaving the same way (also to make the fuzzing work), by introducing a "quirk mode" for the streaming decoder. This quirk mode reproduces the small oddities of the original decoder during parsing. This PR is against netty 5, but if it goes well, I plan to backport the streaming parser to netty 4. My suggestion is to keep the backport in netty-contrib, release a netty 4 version of codec-multipart, and eventually deprecate the form decoder in the netty 4 core repo.
WDYT? |
I've added a |
@violetagg @normanmaurer @trustin Could you see to this? |
Hi, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 adds a new lower-level post body parsing API (PostBodyDecoder). Right now the only implementation is the MultipartDecoder because that's the difficult one, but I plan to implement URL decoding too.
The new API is purely stream-based and leaves the data management (e.g. writing to disk) to the caller. This makes it more compatible with netty 5 buffers, makes buffer lifecycles easier to understand to avoid buffer leaks, and simplifies the implementation to allow for future optimization.
Because multipart is incredibly complex and the old decoder is the result of years of issue reports for compatibility with obscure clients, and I don't have confidence in the existing test coverage, my main focus in this PR has been validating compatibility. To do this, I've ported HttpPostMultipartRequestDecoder to use the new low-level API internally, and created a fuzz test (MultipartComparisonTest) that compares the output with that of the old decoder (HttpPostMultipartRequestDecoderLegacy). This gives me high confidence that there is no feature regression.
In this process, I've found a few behaviors of the old decoder that I consider bugs not worth keeping around. Nonetheless, I've decided to keep HttpPostMultipartRequestDecoder behaving the same way (also to make the fuzzing work), by introducing a "quirk mode" for the streaming decoder. This quirk mode reproduces the small oddities of the original decoder during parsing.
This PR is against netty 5, but if it goes well, I plan to backport the streaming parser to netty 4. My suggestion is to keep the backport in netty-contrib, release a netty 4 version of codec-multipart, and eventually deprecate the form decoder in the netty 4 core repo.