File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
spring-web/src/main/java/org/springframework/http/client Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 3030 * into memory, thus allowing for multiple invocations of {@link #getBody()}.
3131 *
3232 * @author Arjen Poutsma
33+ * @author Juergen Hoeller
3334 * @since 3.1
3435 */
3536final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
3637
3738 private final ClientHttpResponse response ;
3839
3940 @ Nullable
40- private byte [] body ;
41+ private volatile byte [] body ;
4142
4243
4344 BufferingClientHttpResponseWrapper (ClientHttpResponse response ) {
@@ -62,10 +63,17 @@ public HttpHeaders getHeaders() {
6263
6364 @ Override
6465 public InputStream getBody () throws IOException {
65- if (this .body == null ) {
66- this .body = StreamUtils .copyToByteArray (this .response .getBody ());
66+ byte [] body = this .body ;
67+ if (body == null ) {
68+ synchronized (this ) {
69+ body = this .body ;
70+ if (body == null ) {
71+ body = StreamUtils .copyToByteArray (this .response .getBody ());
72+ this .body = body ;
73+ }
74+ }
6775 }
68- return new ByteArrayInputStream (this . body );
76+ return new ByteArrayInputStream (body );
6977 }
7078
7179 @ Override
You can’t perform that action at this time.
0 commit comments