Repository navigation
fix(okhttp): allow explicit Content-Length headers on multipart parts - #9816
Open
Amir-Golmoradi wants to merge 2 commits into
Open
Amir-Golmoradi wants to merge 2 commits into
Amir-Golmoradi wants to merge 2 commits into
Conversation
Contributor
Author
This branch has not been deployed
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
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.
Fixes #9814
#7319 stopped adding
Content-Lengthto multipart parts automatically, butPart.createstill rejects it when supplied explicitly. Callers therefore have no way to include the header.I removed that check. The writer already handles caller-supplied headers and counts their bytes toward the total multipart length. Parts without an explicit header are unchanged.
The outer length is still calculated from each body’s
contentLength(). If a body returns-1, the multipart length remains unknown, regardless of the supplied header.Tests cover both the factory and builder paths, the serialized output, the total byte count, and an unknown-length body with an explicit header. The existing rejection test now verifies that the builder preserves the header.
This patch allows explicit
Content-Lengthheaders for all multipart types. It does not include the FORM-specific restriction or value validation proposed in the issue discussion.The multipart tests,
spotlessCheck, and the fullcheckpass.