1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -244,6 +244,10 @@ public MockRestServiceServerBuilder bufferContent() {
244
244
return this ;
245
245
}
246
246
247
+ protected boolean shouldBufferContent () {
248
+ return this .bufferContent ;
249
+ }
250
+
247
251
@ Override
248
252
public MockRestServiceServer build () {
249
253
if (this .ignoreExpectOrder ) {
@@ -258,9 +262,6 @@ public MockRestServiceServer build() {
258
262
public MockRestServiceServer build (RequestExpectationManager manager ) {
259
263
MockRestServiceServer server = new MockRestServiceServer (manager );
260
264
ClientHttpRequestFactory factory = server .new MockClientHttpRequestFactory ();
261
- if (this .bufferContent ) {
262
- factory = new BufferingClientHttpRequestFactory (factory );
263
- }
264
265
injectRequestFactory (factory );
265
266
return server ;
266
267
}
@@ -281,6 +282,9 @@ private static class RestClientMockRestServiceServerBuilder extends AbstractMock
281
282
282
283
@ Override
283
284
protected void injectRequestFactory (ClientHttpRequestFactory requestFactory ) {
285
+ if (shouldBufferContent ()) {
286
+ this .restClientBuilder .bufferContent ((uri , httpMethod ) -> true );
287
+ }
284
288
this .restClientBuilder .requestFactory (requestFactory );
285
289
}
286
290
}
@@ -297,6 +301,9 @@ private static class RestTemplateMockRestServiceServerBuilder extends AbstractMo
297
301
298
302
@ Override
299
303
protected void injectRequestFactory (ClientHttpRequestFactory requestFactory ) {
304
+ if (shouldBufferContent ()) {
305
+ this .restTemplate .setBufferingPredicate ((uri , httpMethod ) -> true );
306
+ }
300
307
this .restTemplate .setRequestFactory (requestFactory );
301
308
}
302
309
}
0 commit comments