Repository navigation
feat: make multipart form-data filename encoding selectable - #1494
Merged
Merged
Conversation
Motivation: Some multipart receivers do not understand extended filename parameters. Callers need an opt-in output policy without changing existing wire output. Modification: Add explicit Scala and Java FormData render overloads with Extended, Ascii, and PercentEncoded options. Reuse the same part-header rules for strict and streamed entities and preserve Java interface default methods. Keep explicit standalone extended parameters and generic parts unchanged. Result: Callers can opt into lossy ASCII fallback or UTF-8 percent encoding. Existing render calls and incoming decoding do not change. This is an outgoing compatibility option, not a multipart RFC compliance switch. Tests: Focused production compilation with Scala 2.13.18, 3.3.9 and 3.9.0; 12 Scala 2 focused tests and Java strict/streamed interface-wrapper checks on all three outputs. An older-compiled Java caller still runs. Targeted MiMa against the baseline reported zero findings; format and diff checks passed. Full sbt validation and cross-Scala test suites were not run. References: Refs apache#1478. RFC 7578 sections 2 and 4.2.
He-Pin
marked this pull request as ready for review
November 18, 2026 06:51
pjfanning
approved these changes
Nov 18, 2026
pjfanning
left a comment
Member
There was a problem hiding this comment.
lgtm
Nits:
- The scaladsl
toEntity(boundary, encoding)takes the javadslFilenameEncodingenum. A scaladsl alias/vals would save Scala users from importing fromjavadsl(the tests currently pull the constants from the internalBodyPartRenderer). - Building the
RawHeaderby rendering the header twice and slicing off the prefix depends on the shared renderer's output shape. A small dedicated form-data param renderer would be more robust. Asciiwith%in the filename (100%.txt->100?.txt) is not covered by the tests.- It may be worth noting in the scaladoc that
PercentEncodedfilenames are not decoded on the receiving side by Pekko, so they don't round-trip Pekko -> Pekko. - The body mentions "while this is in draft" but the PR is not a draft.
This was referenced Nov 18, 2026
pjfanning
added a commit
to pjfanning/pekko-http
that referenced
this pull request
Nov 18, 2026
Motivation: RFC 7578 allows senders to percent-encode non-ASCII form-data filenames, and apache#1494 added a client-side PercentEncoded option, but servers could only read the raw filename. Modification: Add Scala percentDecodedFilename and Java getPercentDecodedFilename to form-data body parts. They decode UTF-8 percent-escapes and return the raw value when it is not valid percent-encoded UTF-8. filename and getFilename are unchanged. Document the accessor in the HTTP model docs. Result: Applications can opt in to reading percent-encoded filenames. Tests: - MultipartSpec, MultipartFilenameTest, MultipartUnmarshallersSpec References: Fixes apache#1496
pjfanning
added a commit
that referenced
this pull request
Nov 18, 2026
* feat: add opt-in percent-decoded multipart filename accessor Motivation: RFC 7578 allows senders to percent-encode non-ASCII form-data filenames, and #1494 added a client-side PercentEncoded option, but servers could only read the raw filename. Modification: Add Scala percentDecodedFilename and Java getPercentDecodedFilename to form-data body parts. They decode UTF-8 percent-escapes and return the raw value when it is not valid percent-encoded UTF-8. filename and getFilename are unchanged. Document the accessor in the HTTP model docs. Result: Applications can opt in to reading percent-encoded filenames. Tests: - MultipartSpec, MultipartFilenameTest, MultipartUnmarshallersSpec References: Fixes #1496 * test: cover a literal percent sign with every multipart filename encoding
pjfanning
added a commit
that referenced
this pull request
Nov 19, 2026
Motivation: Several recently merged PRs left review points unaddressed: docs that were asked to be dropped, comments and tests that were suggested, and small API and internal tidy-ups. Modification: - Add a Scala FilenameEncoding alias and values to Multipart.FormData and use them in the Scala toEntity signature and tests (#1494). - Render the form-data Content-Disposition header directly instead of rendering it twice and slicing off the prefix (#1494). - Drop the docs paragraph about unpaired URI surrogates (#1426) and the cookie -0000 sentence in request-level.md (#1493). - Fix the javadsl Multipart.FormData doc the same way #1483 fixed the scaladsl one. - Comment the cookie date rule copies so they stay in sync (#1458). - Test custom methods starting with Q next to the QUERY fast path (#1477). - Use one root package import and a dilated timeout in HeaderCompressionSpec (#1438). - Pass isTrailer to HttpMessageRendering.renderHeaders explicitly (#1463). - Remove the unused forwarding overloads in Handshake.Client and EnabledPingState (#1436, #1462). - Move the media type model checks from the routing spec to a new http-core MediaTypesSpec (#1437, #1454). - Hash the WebSocket key without String.valueOf (#1439). Result: The review points are addressed. The only public API change is the added Scala FilenameEncoding alias. Tests: - http-core/testOnly MultipartSpec MultipartsSpec MediaTypesSpec RequestParserCRLFSpec RequestParserLFSpec HeaderCompressionSpec WebSocketClientSpec HeaderSpec HttpHeaderSpec: 314 passed - http2-tests/testOnly HttpMessageRenderingSpec Http2PingSchedulingSpec: 38 passed - http-tests/testOnly FileAndResourceDirectivesSpec: 63 passed - http-core/mimaReportBinaryIssues: passed References: Refs #1426, #1436, #1437, #1438, #1439, #1454, #1458, #1462, #1463, #1477, #1483, #1493, #1494
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.
Motivation
Some multipart receivers do not understand extended filename parameters. Callers need an opt-in outgoing compatibility policy without changing existing wire output.
Modification
Add explicit Scala and Java FormData render overloads with Extended, Ascii and PercentEncoded options. Reuse the same part-header rules for strict and streamed entities and preserve Java interface default methods. Keep explicit standalone filename* parameters and generic parts unchanged.
Result
Callers can opt into lossy ASCII fallback or UTF-8 percent encoding. Existing render calls retain Extended behavior and incoming decoding is unchanged. This is an outgoing compatibility option, not a claim of full multipart RFC compliance.
Tests
Focused production compilation passed with Scala 2.13.18, 3.3.9 and 3.9.0. Twelve Scala 2 focused tests and Java strict/streamed interface-wrapper checks passed on all three compiled outputs. An older-compiled Java caller still runs. Targeted MiMa against the baseline reported zero findings; formatting and diff checks passed. Full sbt validation and cross-Scala test suites were not run.
References
Refs #1478.
RFC 7578 section 2 and section 4.2.
Review focus
@pjfanning, I would appreciate your feedback on the public API shape while this is in draft. In particular, the options are explicit and limited to FormData rendering; explicit standalone filename* is deliberately preserved.