Skip to content

Commit d709a69

Browse files
committed
Remove buffering of encoded parts in MultipartHttpMessageWriter
Closes gh-23518
1 parent 2c5958e commit d709a69

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Optional;
2828
import java.util.concurrent.atomic.AtomicBoolean;
2929
import java.util.function.Supplier;
30-
import java.util.stream.Collectors;
3130

3231
import org.reactivestreams.Publisher;
3332
import reactor.core.publisher.Flux;
@@ -249,8 +248,8 @@ protected byte[] generateMultipartBoundary() {
249248
private Flux<DataBuffer> encodePartValues(
250249
byte[] boundary, String name, List<?> values, DataBufferFactory bufferFactory) {
251250

252-
return Flux.concat(values.stream().map(v ->
253-
encodePart(boundary, name, v, bufferFactory)).collect(Collectors.toList()));
251+
return Flux.fromIterable(values)
252+
.concatMap(value -> encodePart(boundary, name, value, bufferFactory));
254253
}
255254

256255
@SuppressWarnings("unchecked")

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,13 @@ public void shouldSendLargeTextFile() throws IOException {
409409
byte[] expected = Files.readAllBytes(resource.getFile().toPath());
410410
Flux<DataBuffer> body = DataBufferUtils.read(resource, new DefaultDataBufferFactory(), 4096);
411411

412-
this.webClient.post()
412+
Mono<Void> result = this.webClient.post()
413413
.uri("/")
414414
.body(body, DataBuffer.class)
415415
.retrieve()
416-
.bodyToMono(Void.class)
417-
.block(Duration.ofSeconds(5));
416+
.bodyToMono(Void.class);
417+
418+
StepVerifier.create(result).verifyComplete();
418419

419420
expectRequest(request -> {
420421
ByteArrayOutputStream actual = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)