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 ?
|
this.defaultUriVariables = (other.defaultUriVariables != null ?
|
||||||
new LinkedHashMap<>(other.defaultUriVariables) : null);
|
new LinkedHashMap<>(other.defaultUriVariables) : null);
|
||||||
this.uriBuilderFactory = other.uriBuilderFactory;
|
this.uriBuilderFactory = other.uriBuilderFactory;
|
||||||
|
|
||||||
if (other.defaultHeaders != null) {
|
if (other.defaultHeaders != null) {
|
||||||
this.defaultHeaders = new HttpHeaders();
|
this.defaultHeaders = new HttpHeaders();
|
||||||
this.defaultHeaders.putAll(other.defaultHeaders);
|
this.defaultHeaders.putAll(other.defaultHeaders);
|
||||||
@@ -108,13 +109,16 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
|||||||
else {
|
else {
|
||||||
this.defaultHeaders = null;
|
this.defaultHeaders = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.defaultCookies = (other.defaultCookies != null ?
|
this.defaultCookies = (other.defaultCookies != null ?
|
||||||
new LinkedMultiValueMap<>(other.defaultCookies) : null);
|
new LinkedMultiValueMap<>(other.defaultCookies) : null);
|
||||||
this.defaultRequest = other.defaultRequest;
|
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.connector = other.connector;
|
||||||
this.strategies = other.strategies;
|
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;
|
this.exchangeFunction = other.exchangeFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,8 +264,8 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
|||||||
.map(filter -> filter.apply(exchange))
|
.map(filter -> filter.apply(exchange))
|
||||||
.orElse(exchange) : exchange);
|
.orElse(exchange) : exchange);
|
||||||
return new DefaultWebClient(filteredExchange, initUriBuilderFactory(),
|
return new DefaultWebClient(filteredExchange, initUriBuilderFactory(),
|
||||||
this.defaultHeaders != null ? unmodifiableCopy(this.defaultHeaders) : null,
|
this.defaultHeaders != null ? HttpHeaders.readOnlyHttpHeaders(this.defaultHeaders) : null,
|
||||||
this.defaultCookies != null ? unmodifiableCopy(this.defaultCookies) : null,
|
this.defaultCookies != null ? CollectionUtils.unmodifiableMultiValueMap(this.defaultCookies) : null,
|
||||||
this.defaultRequest, new DefaultWebClientBuilder(this));
|
this.defaultRequest, new DefaultWebClientBuilder(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,10 +284,10 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
|||||||
|
|
||||||
private ExchangeStrategies initExchangeStrategies() {
|
private ExchangeStrategies initExchangeStrategies() {
|
||||||
if (CollectionUtils.isEmpty(this.strategiesConfigurers)) {
|
if (CollectionUtils.isEmpty(this.strategiesConfigurers)) {
|
||||||
return this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults();
|
return (this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults());
|
||||||
}
|
}
|
||||||
ExchangeStrategies.Builder builder =
|
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));
|
this.strategiesConfigurers.forEach(configurer -> configurer.accept(builder));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
@@ -292,18 +296,10 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
|
|||||||
if (this.uriBuilderFactory != null) {
|
if (this.uriBuilderFactory != null) {
|
||||||
return this.uriBuilderFactory;
|
return this.uriBuilderFactory;
|
||||||
}
|
}
|
||||||
DefaultUriBuilderFactory factory = this.baseUrl != null ?
|
DefaultUriBuilderFactory factory = (this.baseUrl != null ?
|
||||||
new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory();
|
new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory());
|
||||||
factory.setDefaultUriVariables(this.defaultUriVariables);
|
factory.setDefaultUriVariables(this.defaultUriVariables);
|
||||||
return factory;
|
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