Skip to content

Support StreamingHttpOutputMessage in RestClient #35102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

RazorNd
Copy link
Contributor

@RazorNd RazorNd commented Jun 24, 2025

This pull request ensures proper handling of StreamingHttpOutputMessage
when used with RestClient.

Motivation

Currently, when a StreamingHttpOutputMessage.Body is passed to
RestClient.body(...), the implementation internally calls
body.writeTo(request.getBody()).

However, in AbstractStreamingClientHttpRequest, the getBody() method
returns a ByteArrayOutputStream, and invoking it implicitly switches the
request into buffered mode. This breaks the expected behavior for streaming,
as the user might assume the data will be written directly to the underlying
network stream.

Instead, if the underlying request is an instance of
StreamingHttpOutputMessage, the framework should delegate directly to
setBody(...), which properly supports non-buffered streaming.

Changes

  • Detects if the request is a StreamingHttpOutputMessage
  • Calls setBody(...) instead of getBody().write(...)
  • Preserves fallback behavior for non-streaming clients

Test Coverage

A new integration test has been added to verify that streamed data is
correctly passed through the RestClient without being buffered.

This ensures that behavior is correct across different ClientHttpRequestFactory
implementations.

This commit allows RestClient to handle StreamingHttpOutputMessage
properly by checking the type of the request and invoking setBody()
when appropriate. This improves interoperability with components that
expect streamed output.

A new integration test has been added to verify the functionality.

Signed-off-by: Daniil Razorenov <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 24, 2025
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 24, 2025
@rstoyanchev rstoyanchev self-assigned this Jun 25, 2025
@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 25, 2025
@rstoyanchev rstoyanchev added this to the 6.2.9 milestone Jun 25, 2025
rstoyanchev pushed a commit that referenced this pull request Jun 25, 2025
This commit allows RestClient to handle StreamingHttpOutputMessage
properly by checking the type of the request and invoking setBody()
when appropriate. This improves interoperability with components that
expect streamed output.

A new integration test has been added to verify the functionality.

See gh-35102

Signed-off-by: Daniil Razorenov <[email protected]>
@rstoyanchev
Copy link
Contributor

Thanks for the report and fix. I updated the test to actually fail if buffering is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants