Skip to content

feat: make multipart form-data filename encoding selectable - #1494

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:feat/multipart-filename-encoding
Nov 18, 2026
Merged

He-Pin merged 1 commit into
apache:mainfrom
He-Pin:feat/multipart-filename-encoding

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 18, 2026

Copy link
Copy Markdown
Member

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.

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
He-Pin marked this pull request as ready for review November 18, 2026 06:51

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Nits:

  • The scaladsl toEntity(boundary, encoding) takes the javadsl FilenameEncoding enum. A scaladsl alias/vals would save Scala users from importing from javadsl (the tests currently pull the constants from the internal BodyPartRenderer).
  • Building the RawHeader by 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.
  • Ascii with % in the filename (100%.txt -> 100?.txt) is not covered by the tests.
  • It may be worth noting in the scaladoc that PercentEncoded filenames 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.

@He-Pin
He-Pin merged commit 9ce67ec into apache:main Nov 18, 2026
6 checks passed
@He-Pin
He-Pin deleted the feat/multipart-filename-encoding branch November 18, 2026 09:15
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants