Support StreamingHttpOutputMessage in RestClient

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 <daniltmb@gmail.com>
This commit is contained in:
Daniil Razorenov
2025-06-23 22:54:28 +05:00
committed by rstoyanchev
parent 2477544a8f
commit 8d6117e419
2 changed files with 30 additions and 1 deletions
@@ -16,6 +16,7 @@
package org.springframework.web.client;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -529,6 +530,27 @@ class RestClientIntegrationTests {
});
}
@ParameterizedRestClientTest
void postStreamingMessageBody(ClientHttpRequestFactory requestFactory) {
startServer(requestFactory);
prepareResponse(response -> response.setResponseCode(200));
ResponseEntity<Void> result = this.restClient.post()
.uri("/streaming/body")
.body(new ByteArrayInputStream("test-data".getBytes(UTF_8))::transferTo)
.retrieve()
.toBodilessEntity();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
expectRequestCount(1);
expectRequest(request -> {
assertThat(request.getPath()).isEqualTo("/streaming/body");
assertThat(request.getBody().readUtf8()).isEqualTo("test-data");
});
}
@ParameterizedRestClientTest // gh-31361
public void postForm(ClientHttpRequestFactory requestFactory) {
startServer(requestFactory);