Skip to content

fix(okhttp): allow explicit Content-Length headers on multipart parts - #9816

Open
Amir-Golmoradi wants to merge 2 commits into
lysine-dev:mainfrom
Amir-Golmoradi:fix-multipart-content-length
Open

Amir-Golmoradi wants to merge 2 commits into
lysine-dev:mainfrom
Amir-Golmoradi:fix-multipart-content-length

Conversation

@Amir-Golmoradi

Copy link
Copy Markdown
Contributor

Fixes #9814

#7319 stopped adding Content-Length to multipart parts automatically, but Part.create still 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-Length headers 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 full check pass.

@Amir-Golmoradi

Copy link
Copy Markdown
Contributor Author

@yschimke, could you take a look when you have a chance? You reviewed #7319, which this follows up on.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Cannot add Content-Length header to a multipart part

2 participants