Repository navigation
feat: add streaming support for request bodies in DefaultEncoder - #3396
Merged
Merged
Conversation
yvasyliev
marked this pull request as ready for review
June 7, 2026 13:13
velo
approved these changes
Jun 8, 2026
velo
left a comment
Member
There was a problem hiding this comment.
Thanks for the focused addition. The streaming body support is additive, covered by both encoder-level and request-level tests, and I do not see compatibility or security concerns.
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.
Overview
A second PR in a series related to #2734 feature implementation.
DefaultEncoderpreviously accepted onlyStringandbyte[]body types, forcing callers to buffer file contents or stream data into abyte[]before encoding. This change extendsDefaultEncoderwith native support forFile,Path,InputStream, andRequest.Body, enabling streaming without in-memory buffering.What changed
DefaultEncoder— four newinstanceofbranches dispatch to the appropriateRequest.Bodyimplementation.Fileis normalized toPathbefore dispatch, so both go throughPathBody.Request.PathBody(new) — aBodybacked by a filesystem path. Opens a freshInputStreamon eachwriteTo()call, soisRepeatable()returnstrueand retry-capable clients can re-send the body without special handling.contentLength()returnsFiles.size(path), falling back to-1on I/O error, allowing clients to emit aContent-Lengthheader when the file is accessible.Request.InputStreamBody(new) — aBodybacked by a caller-suppliedInputStream. Because anInputStreamcan only be consumed once,isRepeatable()returnsfalse(interface default) andcontentLength()returns-1(interface default). Callers are responsible for stream lifecycle.Util.copy()— visibility widened fromprivatetopublicso thatPathBodyandInputStreamBodyinRequest.java(thefeign-apimodule) can share the same buffered copy loop.Encoder.javaJavadoc — the example updated to useRequest.Body.of(...)consistent with the v14 API.MIGRATION-v14.md— adds a non-breaking change entry for the newDefaultEncodertypes.Not changed
This is entirely additive. Existing
DefaultEncoderbehaviour forString,byte[], andnullis untouched. No interface changes.Tests
DefaultEncoderTest— unit tests verifycontentLength,isRepeatable, and round-trip body content for all four new types.FeignRequestBodyStreamingTest(new) — end-to-end integration tests againstMockWebServerconfirm the encoded body arrives over the wire correctly forFile,Path,InputStream, andRequest.Body.Closes #220