Avoid unnecessary copy of cookies map in DefaultWebClientBuilder
See gh-25034
This commit is contained in:
@@ -101,6 +101,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
this.defaultUriVariables = (other.defaultUriVariables != null ?
|
||||
new LinkedHashMap<>(other.defaultUriVariables) : null);
|
||||
this.uriBuilderFactory = other.uriBuilderFactory;
|
||||
|
||||
if (other.defaultHeaders != null) {
|
||||
this.defaultHeaders = new HttpHeaders();
|
||||
this.defaultHeaders.putAll(other.defaultHeaders);
|
||||
@@ -108,13 +109,16 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
else {
|
||||
this.defaultHeaders = null;
|
||||
}
|
||||
|
||||
this.defaultCookies = (other.defaultCookies != null ?
|
||||
new LinkedMultiValueMap<>(other.defaultCookies) : null);
|
||||
this.defaultRequest = other.defaultRequest;
|
||||
this.filters = other.filters != null ? new ArrayList<>(other.filters) : null;
|
||||
this.filters = (other.filters != null ? new ArrayList<>(other.filters) : null);
|
||||
|
||||
this.connector = other.connector;
|
||||
this.strategies = other.strategies;
|
||||
this.strategiesConfigurers = other.strategiesConfigurers != null ? new ArrayList<>(other.strategiesConfigurers) : null;
|
||||
this.strategiesConfigurers = (other.strategiesConfigurers != null ?
|
||||
new ArrayList<>(other.strategiesConfigurers) : null);
|
||||
this.exchangeFunction = other.exchangeFunction;
|
||||
}
|
||||
|
||||
@@ -260,8 +264,8 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
.map(filter -> filter.apply(exchange))
|
||||
.orElse(exchange) : exchange);
|
||||
return new DefaultWebClient(filteredExchange, initUriBuilderFactory(),
|
||||
this.defaultHeaders != null ? unmodifiableCopy(this.defaultHeaders) : null,
|
||||
this.defaultCookies != null ? unmodifiableCopy(this.defaultCookies) : null,
|
||||
this.defaultHeaders != null ? HttpHeaders.readOnlyHttpHeaders(this.defaultHeaders) : null,
|
||||
this.defaultCookies != null ? CollectionUtils.unmodifiableMultiValueMap(this.defaultCookies) : null,
|
||||
this.defaultRequest, new DefaultWebClientBuilder(this));
|
||||
}
|
||||
|
||||
@@ -280,10 +284,10 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
|
||||
private ExchangeStrategies initExchangeStrategies() {
|
||||
if (CollectionUtils.isEmpty(this.strategiesConfigurers)) {
|
||||
return this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults();
|
||||
return (this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults());
|
||||
}
|
||||
ExchangeStrategies.Builder builder =
|
||||
this.strategies != null ? this.strategies.mutate() : ExchangeStrategies.builder();
|
||||
(this.strategies != null ? this.strategies.mutate() : ExchangeStrategies.builder());
|
||||
this.strategiesConfigurers.forEach(configurer -> configurer.accept(builder));
|
||||
return builder.build();
|
||||
}
|
||||
@@ -292,18 +296,10 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
||||
if (this.uriBuilderFactory != null) {
|
||||
return this.uriBuilderFactory;
|
||||
}
|
||||
DefaultUriBuilderFactory factory = this.baseUrl != null ?
|
||||
new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory();
|
||||
DefaultUriBuilderFactory factory = (this.baseUrl != null ?
|
||||
new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory());
|
||||
factory.setDefaultUriVariables(this.defaultUriVariables);
|
||||
return factory;
|
||||
}
|
||||
|
||||
private static HttpHeaders unmodifiableCopy(HttpHeaders headers) {
|
||||
return HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
}
|
||||
|
||||
private static <K, V> MultiValueMap<K, V> unmodifiableCopy(MultiValueMap<K, V> map) {
|
||||
return CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(map));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user