Skip to content

feat: add streaming support for request bodies in DefaultEncoder - #3396

Merged
velo merged 2 commits into
OpenFeign:14.xfrom
yvasyliev:feature/streaming-body-encoding
Jun 8, 2026
Merged

velo merged 2 commits into
OpenFeign:14.xfrom
yvasyliev:feature/streaming-body-encoding

Conversation

@yvasyliev

Copy link
Copy Markdown
Contributor

Overview

A second PR in a series related to #2734 feature implementation.

DefaultEncoder previously accepted only String and byte[] body types, forcing callers to buffer file contents or stream data into a byte[] before encoding. This change extends DefaultEncoder with native support for File, Path, InputStream, and Request.Body, enabling streaming without in-memory buffering.

What changed

DefaultEncoder — four new instanceof branches dispatch to the appropriate Request.Body implementation. File is normalized to Path before dispatch, so both go through PathBody.

Request.PathBody (new) — a Body backed by a filesystem path. Opens a fresh InputStream on each writeTo() call, so isRepeatable() returns true and retry-capable clients can re-send the body without special handling. contentLength() returns Files.size(path), falling back to -1 on I/O error, allowing clients to emit a Content-Length header when the file is accessible.

Request.InputStreamBody (new) — a Body backed by a caller-supplied InputStream. Because an InputStream can only be consumed once, isRepeatable() returns false (interface default) and contentLength() returns -1 (interface default). Callers are responsible for stream lifecycle.

Util.copy() — visibility widened from private to public so that PathBody and InputStreamBody in Request.java (the feign-api module) can share the same buffered copy loop.

Encoder.java Javadoc — the example updated to use Request.Body.of(...) consistent with the v14 API.

MIGRATION-v14.md — adds a non-breaking change entry for the new DefaultEncoder types.

Not changed

This is entirely additive. Existing DefaultEncoder behaviour for String, byte[], and null is untouched. No interface changes.

Tests

  • DefaultEncoderTest — unit tests verify contentLength, isRepeatable, and round-trip body content for all four new types.
  • FeignRequestBodyStreamingTest (new) — end-to-end integration tests against MockWebServer confirm the encoded body arrives over the wire correctly for File, Path, InputStream, and Request.Body.

Closes #220

@velo velo 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.

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.

@velo
velo merged commit 2fe3f1c into OpenFeign:14.x Jun 8, 2026
3 checks passed
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