Add customizer variant of requestFactorySettings
Add `requestFactorySettings` that accepts a `UnaryOperator` so that the existing `requestFactorySettings` can be customized rather than replaced. Closes gh-43258
This commit is contained in:
@@ -25,6 +25,7 @@ import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
@@ -974,6 +975,22 @@ public class TestRestTemplate {
|
||||
this.restTemplate.getUriTemplateHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code TestRestTemplate} with the same configuration as this one,
|
||||
* except that it will customize the {@link ClientHttpRequestFactorySettings}. The
|
||||
* request factory used is a new instance of the underlying {@link RestTemplate}'s
|
||||
* request factory type (when possible).
|
||||
* @param requestFactorySettingsCustomizer a {@link UnaryOperator} to update the
|
||||
* settings
|
||||
* @return the new template
|
||||
* @since 3.4.1
|
||||
*/
|
||||
public TestRestTemplate withRequestFactorySettings(
|
||||
UnaryOperator<ClientHttpRequestFactorySettings> requestFactorySettingsCustomizer) {
|
||||
return new TestRestTemplate(this.builder.requestFactorySettings(requestFactorySettingsCustomizer),
|
||||
this.restTemplate.getUriTemplateHandler());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private RequestEntity<?> createRequestEntityWithRootAppliedUri(RequestEntity<?> requestEntity) {
|
||||
return new RequestEntity(requestEntity.getBody(), requestEntity.getHeaders(), requestEntity.getMethod(),
|
||||
|
||||
Reference in New Issue
Block a user