|
16 | 16 |
|
17 | 17 | package org.springframework.web.client;
|
18 | 18 |
|
| 19 | +import java.io.ByteArrayInputStream; |
19 | 20 | import java.io.IOException;
|
20 | 21 | import java.lang.annotation.ElementType;
|
21 | 22 | import java.lang.annotation.Retention;
|
|
44 | 45 | import org.springframework.http.HttpStatusCode;
|
45 | 46 | import org.springframework.http.MediaType;
|
46 | 47 | import org.springframework.http.ResponseEntity;
|
| 48 | +import org.springframework.http.StreamingHttpOutputMessage; |
47 | 49 | import org.springframework.http.client.ClientHttpRequestFactory;
|
48 | 50 | import org.springframework.http.client.ClientHttpRequestInterceptor;
|
49 | 51 | import org.springframework.http.client.ClientHttpResponse;
|
|
53 | 55 | import org.springframework.http.client.ReactorClientHttpRequestFactory;
|
54 | 56 | import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
55 | 57 | import org.springframework.util.CollectionUtils;
|
| 58 | +import org.springframework.util.FastByteArrayOutputStream; |
56 | 59 | import org.springframework.util.FileCopyUtils;
|
57 | 60 | import org.springframework.util.LinkedMultiValueMap;
|
58 | 61 | import org.springframework.util.MultiValueMap;
|
@@ -602,6 +605,30 @@ public void postForm(ClientHttpRequestFactory requestFactory) {
|
602 | 605 | });
|
603 | 606 | }
|
604 | 607 |
|
| 608 | + @ParameterizedRestClientTest // gh-35102 |
| 609 | + void postStreamingBody(ClientHttpRequestFactory requestFactory) { |
| 610 | + startServer(requestFactory); |
| 611 | + prepareResponse(response -> response.setResponseCode(200)); |
| 612 | + |
| 613 | + StreamingHttpOutputMessage.Body testBody = out -> { |
| 614 | + assertThat(out).as("Not a streaming response").isNotInstanceOf(FastByteArrayOutputStream.class); |
| 615 | + new ByteArrayInputStream("test-data".getBytes(UTF_8)).transferTo(out); |
| 616 | + }; |
| 617 | + |
| 618 | + ResponseEntity<Void> result = this.restClient.post() |
| 619 | + .uri("/streaming/body") |
| 620 | + .body(testBody) |
| 621 | + .retrieve() |
| 622 | + .toBodilessEntity(); |
| 623 | + |
| 624 | + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 625 | + |
| 626 | + expectRequestCount(1); |
| 627 | + expectRequest(request -> { |
| 628 | + assertThat(request.getPath()).isEqualTo("/streaming/body"); |
| 629 | + assertThat(request.getBody().readUtf8()).isEqualTo("test-data"); |
| 630 | + }); |
| 631 | + } |
605 | 632 |
|
606 | 633 | @ParameterizedRestClientTest
|
607 | 634 | void statusHandler(ClientHttpRequestFactory requestFactory) {
|
|
0 commit comments