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 3131 * into memory, thus allowing for multiple invocations of {@link #getBody()}.
3232 *
3333 * @author Arjen Poutsma
34+ * @author Juergen Hoeller
3435 * @since 3.1
3536 */
3637final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
3738
3839 private final ClientHttpResponse response ;
3940
40- private byte @ Nullable [] body ;
41+ private volatile byte @ Nullable [] 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