Skip to content

Commit b4bec4c

Browse files
committed
Allow repeatable writes in Client Interceptors
See gh-31449
1 parent 48da952 commit b4bec4c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.http.client;
1818

1919
import java.io.IOException;
20+
import java.io.OutputStream;
2021
import java.net.URI;
2122
import java.util.Iterator;
2223
import java.util.List;
@@ -92,7 +93,17 @@ public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOExc
9293
request.getHeaders().forEach((key, value) -> delegate.getHeaders().addAll(key, value));
9394
if (body.length > 0) {
9495
if (delegate instanceof StreamingHttpOutputMessage streamingOutputMessage) {
95-
streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(body, outputStream));
96+
streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() {
97+
@Override
98+
public void writeTo(OutputStream outputStream) throws IOException {
99+
StreamUtils.copy(body, outputStream);
100+
}
101+
102+
@Override
103+
public boolean repeatable() {
104+
return true;
105+
}
106+
});
96107
}
97108
else {
98109
StreamUtils.copy(body, delegate.getBody());

0 commit comments

Comments
 (0)