mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
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:
committed by
rstoyanchev
parent
2477544a8f
commit
8d6117e419
+22
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user