From 65b09be6694254376d6d5eeaab6dd29c0b6d92f7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 6 Jun 2020 16:10:20 +0200 Subject: [PATCH] Polishing --- .../core/io/DefaultResourceLoader.java | 2 +- .../java/org/springframework/http/HttpHeaders.java | 13 +++++++++++++ .../function/client/DefaultWebClientBuilder.java | 10 ++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java b/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java index 09fbbfd25b..27ed3bf1a0 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java @@ -79,7 +79,7 @@ public class DefaultResourceLoader implements ResourceLoader { * Specify the ClassLoader to load class path resources with, or {@code null} * for using the thread context class loader at the time of actual resource access. *

The default is that ClassLoader access will happen using the thread context - * class loader at the time of this ResourceLoader's initialization. + * class loader at the time of actual resource access (since 5.3). */ public void setClassLoader(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 9c07ada076..9c547634b2 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -1768,6 +1768,19 @@ public class HttpHeaders implements MultiValueMap, Serializable } + /** + * Apply a read-only {@code HttpHeaders} wrapper around the given headers, if necessary. + *

Also caches the parsed representations of the "Accept" and "Content-Type" headers. + * @param headers the headers to expose + * @return a read-only variant of the headers, or the original headers as-is + * (in case it happens to be a read-only {@code HttpHeaders} instance already) + * @since 5.3 + */ + public static HttpHeaders readOnlyHttpHeaders(MultiValueMap headers) { + return (headers instanceof HttpHeaders ? + readOnlyHttpHeaders((HttpHeaders) headers) : new ReadOnlyHttpHeaders(headers)); + } + /** * Apply a read-only {@code HttpHeaders} wrapper around the given headers, if necessary. *

Also caches the parsed representations of the "Accept" and "Content-Type" headers. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index f7ba51ed10..0b87db5546 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -229,7 +229,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder { } @Override - @SuppressWarnings("deprecation") + @Deprecated public WebClient.Builder exchangeStrategies(Consumer configurer) { if (this.strategiesConfigurers == null) { this.strategiesConfigurers = new ArrayList<>(4); @@ -266,7 +266,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder { .orElse(exchange) : exchange); return new DefaultWebClient(filteredExchange, initUriBuilderFactory(), this.defaultHeaders != null ? HttpHeaders.readOnlyHttpHeaders(this.defaultHeaders) : null, - this.defaultCookies != null ? HttpHeaders.readOnlyHttpHeaders(this.defaultCookies) : null, + this.defaultCookies != null ? CollectionUtils.unmodifiableMultiValueMap(this.defaultCookies) : null, this.defaultRequest, new DefaultWebClientBuilder(this)); } @@ -290,10 +290,8 @@ final class DefaultWebClientBuilder implements WebClient.Builder { if (CollectionUtils.isEmpty(this.strategiesConfigurers)) { return this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults(); } - ExchangeStrategies.Builder builder = this.strategies != null ? this.strategies.mutate() : ExchangeStrategies.builder(); - this.strategiesConfigurers.forEach(configurer -> configurer.accept(builder)); return builder.build(); } @@ -308,8 +306,4 @@ final class DefaultWebClientBuilder implements WebClient.Builder { return factory; } - private static MultiValueMap unmodifiableCopy(MultiValueMap map) { - return CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(map)); - } - }