11/* 
2-  * Copyright 2002-2023  the original author or authors. 
2+  * Copyright 2002-2025  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. 
@@ -244,6 +244,10 @@ public MockRestServiceServerBuilder bufferContent() {
244244			return  this ;
245245		}
246246
247+ 		protected  boolean  shouldBufferContent () {
248+ 			return  this .bufferContent ;
249+ 		}
250+ 
247251		@ Override 
248252		public  MockRestServiceServer  build () {
249253			if  (this .ignoreExpectOrder ) {
@@ -258,9 +262,6 @@ public MockRestServiceServer build() {
258262		public  MockRestServiceServer  build (RequestExpectationManager  manager ) {
259263			MockRestServiceServer  server  = new  MockRestServiceServer (manager );
260264			ClientHttpRequestFactory  factory  = server .new  MockClientHttpRequestFactory ();
261- 			if  (this .bufferContent ) {
262- 				factory  = new  BufferingClientHttpRequestFactory (factory );
263- 			}
264265			injectRequestFactory (factory );
265266			return  server ;
266267		}
@@ -281,6 +282,9 @@ private static class RestClientMockRestServiceServerBuilder extends AbstractMock
281282
282283		@ Override 
283284		protected  void  injectRequestFactory (ClientHttpRequestFactory  requestFactory ) {
285+ 			if  (shouldBufferContent ()) {
286+ 				this .restClientBuilder .bufferContent ((uri , httpMethod ) -> true );
287+ 			}
284288			this .restClientBuilder .requestFactory (requestFactory );
285289		}
286290	}
@@ -297,6 +301,9 @@ private static class RestTemplateMockRestServiceServerBuilder extends AbstractMo
297301
298302		@ Override 
299303		protected  void  injectRequestFactory (ClientHttpRequestFactory  requestFactory ) {
304+ 			if  (shouldBufferContent ()) {
305+ 				this .restTemplate .setBufferingPredicate ((uri , httpMethod ) -> true );
306+ 			}
300307			this .restTemplate .setRequestFactory (requestFactory );
301308		}
302309	}
0 commit comments