Skip to content

Commit 95b83fe

Browse files
committed
Add zero copy support in reactor-based WebClient
This commit makes Reactor Netty `WebClient` instances support zero-copy requests by implementing `ZeroCopyHttpOutputMessage`. The implementation leverages the optimized `sendFile` mechanism if available.
1 parent 80979e7 commit 95b83fe

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.http.client.reactive;
1818

19+
import java.io.File;
1920
import java.net.URI;
2021
import java.util.Collection;
2122

@@ -30,6 +31,7 @@
3031
import org.springframework.core.io.buffer.DataBufferFactory;
3132
import org.springframework.core.io.buffer.NettyDataBufferFactory;
3233
import org.springframework.http.HttpMethod;
34+
import org.springframework.http.ZeroCopyHttpOutputMessage;
3335

3436
/**
3537
* {@link ClientHttpRequest} implementation for the Reactor-Netty HTTP client.
@@ -38,7 +40,7 @@
3840
* @since 5.0
3941
* @see reactor.ipc.netty.http.client.HttpClient
4042
*/
41-
public class ReactorClientHttpRequest extends AbstractClientHttpRequest {
43+
public class ReactorClientHttpRequest extends AbstractClientHttpRequest implements ZeroCopyHttpOutputMessage {
4244

4345
private final HttpMethod httpMethod;
4446

@@ -89,6 +91,11 @@ private static Publisher<ByteBuf> toByteBufs(Publisher<? extends DataBuffer> dat
8991
return Flux.from(dataBuffers).map(NettyDataBufferFactory::toByteBuf);
9092
}
9193

94+
@Override
95+
public Mono<Void> writeWith(File file, long position, long count) {
96+
return doCommit(() -> this.httpRequest.sendFile(file.toPath(), position, count).then());
97+
}
98+
9299
@Override
93100
public Mono<Void> setComplete() {
94101
return doCommit(() -> httpRequest.sendHeaders().then());

0 commit comments

Comments
 (0)