mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
Merge branch '6.2.x'
# Conflicts: # spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java
This commit is contained in:
+12
-4
@@ -31,13 +31,14 @@ import org.springframework.util.StreamUtils;
|
||||
* into memory, thus allowing for multiple invocations of {@link #getBody()}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
|
||||
|
||||
private final ClientHttpResponse response;
|
||||
|
||||
private byte @Nullable [] body;
|
||||
private volatile byte @Nullable [] body;
|
||||
|
||||
|
||||
BufferingClientHttpResponseWrapper(ClientHttpResponse response) {
|
||||
@@ -62,10 +63,17 @@ final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
|
||||
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
if (this.body == null) {
|
||||
this.body = StreamUtils.copyToByteArray(this.response.getBody());
|
||||
byte[] body = this.body;
|
||||
if (body == null) {
|
||||
synchronized (this) {
|
||||
body = this.body;
|
||||
if (body == null) {
|
||||
body = StreamUtils.copyToByteArray(this.response.getBody());
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ByteArrayInputStream(this.body);
|
||||
return new ByteArrayInputStream(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user