Skip to content

Normalize multipart requests converted from WebTestClient - #1092

Closed
AbineshDev01 wants to merge 1 commit into
spring-projects:4.0.xfrom
AbineshDev01:fix/multipart-converter-content-1075-track-a
Closed

AbineshDev01 wants to merge 1 commit into
spring-projects:4.0.xfrom
AbineshDev01:fix/multipart-converter-content-1075-track-a

Conversation

@AbineshDev01

Copy link
Copy Markdown

Summary

Fix multipart request snippets produced with WebTestClient so that the request is represented by its parsed parts rather than both those parts and the raw multipart payload.

Fixes #1075.

Root Cause

WebTestClientRequestConverter supplies the wire body and the parsed parts to OperationRequestFactory. This makes curl combine -F and -d, HTTPie combine request items and stdin, and the HTTP request snippet append its own boundary to the original transport boundary.

Changes

  • When parts have been extracted, omit the raw body and remove the transport boundary parameter case-insensitively while preserving other content-type parameters and the original exchange headers. Preserve raw bodies when no parts can be extracted.
  • Read all buffers of file-backed parts rather than stopping after the first buffer, releasing written buffers. Parts are now the only multipart payload, so large uploads must not be truncated.
  • Render multipart parts in HTTP request snippets for DELETE as well as POST/PUT/PATCH, so normalizing the request does not discard an existing DELETE body.
  • Cover plain/malformed multipart fallback, repeated/empty parts, filename/binary content including a 300 KB upload, uppercase boundary parameters, and generated curl/HTTPie/HTTP snippets across POST/PUT/PATCH/DELETE. The core DELETE regression runs with both Asciidoctor and Markdown templates.

This targets 4.0.x, matching the issue's milestone and recent fixes. The newer RestTestClient converter on main has the same original problem and will need the corresponding normalization when this change is forward-ported; that module does not exist on 4.0.x.

Testing

  • Observed the new multipart regressions fail against the original converter (20 tests, 4 failures); observed separate uppercase-boundary, multipart DELETE, and 300 KB file regressions fail before their corrections.

  • ./gradlew test --no-daemon --no-parallel --max-workers=2 -Dorg.gradle.jvmargs='-Xmx1536m -Dfile.encoding=UTF-8' — passed, 1,122 tests, zero failures/errors/skipped test cases (61 Asciidoctor, 945 core, 77 MockMvc, 39 WebTestClient). The docs project's test task is disabled by its existing build convention.

  • ./gradlew :spring-restdocs-core:format :spring-restdocs-webtestclient:format ... — passed; formatting was run separately because combining format and compile in one invocation triggers Gradle 9's existing implicit-dependency validation.

  • ./gradlew build --continue --init-script /path/to/private/javadoc-tool.gradle --no-daemon --no-parallel --max-workers=2 -Dorg.gradle.jvmargs='-Xmx1536m -Dfile.encoding=UTF-8' — passed, including compilation/NullAway, checkstyle main/test/test-fixtures, formatting, NoHTTP, jars/Javadocs and Antora documentation. Gradle, npm and XDG caches were directed to writable workspace directories; no checks were excluded. Existing Javadoc missing-constructor-comment and VM/color warnings were nonfatal.

Tooling: isolated Temurin 21.0.13 for Gradle/compiler/tests, Java 17 release target unchanged. The initially installed 21.0.2 was too old for NullAway JSpecify mode. The build unconditionally requests --no-fonts, which JDK 21 Javadoc does not support, so a private external Gradle init script selects the installed JDK 27 Javadoc executable only; no project build files or checks are changed/disabled.

AI assistance was used for investigation, implementation, and tests; the final diff also received independent review, whose correctness findings were reproduced with regression tests and addressed.

Represent successfully parsed multipart requests using their parts only and remove the transport boundary while retaining other media type parameters. Preserve unparsed raw content, read complete file parts and retain multipart bodies for DELETE HTTP snippets.

Fixes spring-projectsgh-1075

Signed-off-by: Abinesh <abineshr8525@gmail.com>
@wilkinsona

Copy link
Copy Markdown
Member

Thanks for the PR, but @chuuminggg has already offered to contribute a fix and we're happy to wait for that to happen.

@wilkinsona wilkinsona closed this Nov 16, 2026
@wilkinsona wilkinsona added status: declined Suggestion or change that we don't want to make at this time and removed status: waiting-for-triage Untriaged issue labels Nov 16, 2026
@AbineshDev01

Copy link
Copy Markdown
Author

Understood. I’ll leave #1075 to @chuuminggg and won’t pursue this PR further.

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

Labels

status: declined Suggestion or change that we don't want to make at this time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants