Move spring.http.* config properties namespace

Closes gh-18827
This commit is contained in:
Brian Clozel
2020-01-14 10:45:31 +01:00
parent 7f6b01c3d2
commit 711391cf2f
15 changed files with 300 additions and 205 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,11 @@ import org.springframework.util.unit.DataSize;
@ConfigurationProperties(prefix = "spring.codec")
public class CodecProperties {
/**
* Whether to log form data at DEBUG level, and headers at TRACE level.
*/
private boolean logRequestDetails;
/**
* Limit on the number of bytes that can be buffered whenever the input stream needs
* to be aggregated. By default this is not set, in which case individual codec
@@ -35,6 +40,14 @@ public class CodecProperties {
*/
private DataSize maxInMemorySize;
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public DataSize getMaxInMemorySize() {
return this.maxInMemorySize;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration.NotReactiveWebApplicationCondition;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
@@ -60,7 +61,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
JsonbHttpMessageConvertersConfiguration.class })
public class HttpMessageConvertersAutoConfiguration {
static final String PREFERRED_MAPPER_PROPERTY = "spring.http.converters.preferred-json-mapper";
static final String PREFERRED_MAPPER_PROPERTY = "spring.mvc.converters.preferred-json-mapper";
@Bean
@ConditionalOnMissingBean
@@ -70,14 +71,14 @@ public class HttpMessageConvertersAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(StringHttpMessageConverter.class)
@EnableConfigurationProperties(HttpProperties.class)
@EnableConfigurationProperties(ServerProperties.class)
protected static class StringHttpMessageConverterConfiguration {
@Bean
@ConditionalOnMissingBean
public StringHttpMessageConverter stringHttpMessageConverter(HttpProperties httpProperties) {
public StringHttpMessageConverter stringHttpMessageConverter(ServerProperties serverProperties) {
StringHttpMessageConverter converter = new StringHttpMessageConverter(
httpProperties.getEncoding().getCharset());
serverProperties.getServlet().getEncoding().getCharset());
converter.setWriteAcceptCharset(false);
return converter;
}

View File

@@ -1,154 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.http;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* HTTP properties.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @author Brian Clozel
* @since 2.1.0
*/
@ConfigurationProperties(prefix = "spring.http")
public class HttpProperties {
/**
* Whether logging of (potentially sensitive) request details at DEBUG and TRACE level
* is allowed.
*/
private boolean logRequestDetails;
/**
* HTTP encoding properties.
*/
private final Encoding encoding = new Encoding();
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public Encoding getEncoding() {
return this.encoding;
}
/**
* Configuration properties for http encoding.
*/
public static class Encoding {
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
/**
* Charset of HTTP requests and responses. Added to the "Content-Type" header if
* not set explicitly.
*/
private Charset charset = DEFAULT_CHARSET;
/**
* Whether to force the encoding to the configured charset on HTTP requests and
* responses.
*/
private Boolean force;
/**
* Whether to force the encoding to the configured charset on HTTP requests.
* Defaults to true when "force" has not been specified.
*/
private Boolean forceRequest;
/**
* Whether to force the encoding to the configured charset on HTTP responses.
*/
private Boolean forceResponse;
/**
* Locale in which to encode mapping.
*/
private Map<Locale, Charset> mapping;
public Charset getCharset() {
return this.charset;
}
public void setCharset(Charset charset) {
this.charset = charset;
}
public boolean isForce() {
return Boolean.TRUE.equals(this.force);
}
public void setForce(boolean force) {
this.force = force;
}
public boolean isForceRequest() {
return Boolean.TRUE.equals(this.forceRequest);
}
public void setForceRequest(boolean forceRequest) {
this.forceRequest = forceRequest;
}
public boolean isForceResponse() {
return Boolean.TRUE.equals(this.forceResponse);
}
public void setForceResponse(boolean forceResponse) {
this.forceResponse = forceResponse;
}
public Map<Locale, Charset> getMapping() {
return this.mapping;
}
public void setMapping(Map<Locale, Charset> mapping) {
this.mapping = mapping;
}
public boolean shouldForce(Type type) {
Boolean force = (type != Type.REQUEST) ? this.forceResponse : this.forceRequest;
if (force == null) {
force = this.force;
}
if (force == null) {
force = (type == Type.REQUEST);
}
return force;
}
public enum Type {
REQUEST, RESPONSE
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.codec.CodecProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
@@ -49,7 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ CodecConfigurer.class, WebClient.class })
@AutoConfigureAfter(JacksonAutoConfiguration.class)
@EnableConfigurationProperties({ HttpProperties.class, CodecProperties.class })
@EnableConfigurationProperties(CodecProperties.class)
public class CodecsAutoConfiguration {
private static final MimeType[] EMPTY_MIME_TYPES = {};
@@ -76,11 +75,11 @@ public class CodecsAutoConfiguration {
@Bean
@Order(0)
CodecCustomizer defaultCodecCustomizer(HttpProperties httpProperties, CodecProperties codecProperties) {
CodecCustomizer defaultCodecCustomizer(CodecProperties codecProperties) {
return (configurer) -> {
PropertyMapper map = PropertyMapper.get();
CodecConfigurer.DefaultCodecs defaultCodecs = configurer.defaultCodecs();
defaultCodecs.enableLoggingRequestDetails(httpProperties.isLogRequestDetails());
defaultCodecs.enableLoggingRequestDetails(codecProperties.isLogRequestDetails());
map.from(codecProperties.getMaxInMemorySize()).whenNonNull().asInt(DataSize::toBytes)
.to(defaultCodecs::maxInMemorySize);
};

View File

@@ -37,6 +37,7 @@ import org.springframework.boot.convert.DurationUnit;
import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.servlet.server.Encoding;
import org.springframework.boot.web.servlet.server.Jsp;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.util.StringUtils;
@@ -246,6 +247,9 @@ public class ServerProperties {
*/
private String applicationDisplayName = "application";
@NestedConfigurationProperty
private final Encoding encoding = new Encoding();
@NestedConfigurationProperty
private final Jsp jsp = new Jsp();
@@ -280,6 +284,10 @@ public class ServerProperties {
return this.contextParameters;
}
public Encoding getEncoding() {
return this.encoding;
}
public Jsp getJsp() {
return this.jsp;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@@ -83,17 +82,17 @@ public class DispatcherServletAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@Conditional(DefaultDispatcherServletCondition.class)
@ConditionalOnClass(ServletRegistration.class)
@EnableConfigurationProperties({ HttpProperties.class, WebMvcProperties.class })
@EnableConfigurationProperties(WebMvcProperties.class)
protected static class DispatcherServletConfiguration {
@Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
public DispatcherServlet dispatcherServlet(HttpProperties httpProperties, WebMvcProperties webMvcProperties) {
public DispatcherServlet dispatcherServlet(WebMvcProperties webMvcProperties) {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setDispatchOptionsRequest(webMvcProperties.isDispatchOptionsRequest());
dispatcherServlet.setDispatchTraceRequest(webMvcProperties.isDispatchTraceRequest());
dispatcherServlet.setThrowExceptionIfNoHandlerFound(webMvcProperties.isThrowExceptionIfNoHandlerFound());
dispatcherServlet.setPublishEvents(webMvcProperties.isPublishRequestHandledEvents());
dispatcherServlet.setEnableLoggingRequestDetails(httpProperties.isLogRequestDetails());
dispatcherServlet.setEnableLoggingRequestDetails(webMvcProperties.isLogRequestDetails());
return dispatcherServlet;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.autoconfigure.http.HttpProperties.Encoding.Type;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.server.Encoding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
@@ -41,16 +41,16 @@ import org.springframework.web.filter.CharacterEncodingFilter;
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(HttpProperties.class)
@EnableConfigurationProperties(ServerProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(CharacterEncodingFilter.class)
@ConditionalOnProperty(prefix = "spring.http.encoding", value = "enabled", matchIfMissing = true)
@ConditionalOnProperty(prefix = "server.servlet.encoding", value = "enabled", matchIfMissing = true)
public class HttpEncodingAutoConfiguration {
private final HttpProperties.Encoding properties;
private final Encoding properties;
public HttpEncodingAutoConfiguration(HttpProperties properties) {
this.properties = properties.getEncoding();
public HttpEncodingAutoConfiguration(ServerProperties properties) {
this.properties = properties.getServlet().getEncoding();
}
@Bean
@@ -58,8 +58,8 @@ public class HttpEncodingAutoConfiguration {
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
filter.setEncoding(this.properties.getCharset().name());
filter.setForceRequestEncoding(this.properties.shouldForce(Type.REQUEST));
filter.setForceResponseEncoding(this.properties.shouldForce(Type.RESPONSE));
filter.setForceRequestEncoding(this.properties.shouldForce(Encoding.Type.REQUEST));
filter.setForceResponseEncoding(this.properties.shouldForce(Encoding.Type.RESPONSE));
return filter;
}
@@ -71,9 +71,9 @@ public class HttpEncodingAutoConfiguration {
static class LocaleCharsetMappingsCustomizer
implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>, Ordered {
private final HttpProperties.Encoding properties;
private final Encoding properties;
LocaleCharsetMappingsCustomizer(HttpProperties.Encoding properties) {
LocaleCharsetMappingsCustomizer(Encoding properties) {
this.properties = properties;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,6 +87,12 @@ public class WebMvcProperties {
*/
private boolean throwExceptionIfNoHandlerFound = false;
/**
* Whether logging of (potentially sensitive) request details at DEBUG and TRACE level
* is allowed.
*/
private boolean logRequestDetails;
/**
* Whether to enable warn logging of exceptions resolved by a
* "HandlerExceptionResolver", except for "DefaultHandlerExceptionResolver".
@@ -164,6 +170,14 @@ public class WebMvcProperties {
this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound;
}
public boolean isLogRequestDetails() {
return this.logRequestDetails;
}
public void setLogRequestDetails(boolean logRequestDetails) {
this.logRequestDetails = logRequestDetails;
}
public boolean isLogResolvedException() {
return this.logResolvedException;
}

View File

@@ -473,16 +473,94 @@
"defaultValue": ".tpl"
},
{
"name": "spring.http.encoding.enabled",
"name": "server.servlet.encoding.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable http encoding support.",
"defaultValue": true
},
{
"name": "spring.http.converters.preferred-json-mapper",
"name": "spring.http.encoding.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable http encoding support.",
"defaultValue": true,
"deprecation" : {
"replacement" : "server.servlet.encoding.enabled",
"level" : "error"
}
},
{
"name" : "spring.http.encoding.charset",
"type": "java.nio.charset.Charset",
"description" : "Charset of HTTP requests and responses. Added to the Content-Type header if not set explicitly.",
"deprecation" : {
"replacement" : "server.servlet.encoding.charset",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP requests and responses.",
"defaultValue": false,
"deprecation" : {
"replacement" : "server.servlet.encoding.force",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force-request",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP requests. Defaults to true when force has not been specified.",
"defaultValue": true,
"deprecation" : {
"replacement" : "server.servlet.encoding.force-request",
"level" : "error"
}
},
{
"name": "spring.http.encoding.force-response",
"type": "java.lang.Boolean",
"description": "Whether to force the encoding to the configured charset on HTTP responses.",
"defaultValue": false,
"deprecation" : {
"replacement" : "server.servlet.encoding.force-response",
"level" : "error"
}
},
{
"name" : "spring.http.encoding.mapping",
"type" : "java.util.Map<java.util.Locale,java.nio.charset.Charset>",
"description" : "Locale in which to encode mapping.",
"deprecation" : {
"replacement" : "server.servlet.encoding.mapping",
"level" : "error"
}
},
{
"name": "spring.http.log-request-details",
"type": "java.lang.Boolean",
"description": "Whether logging of (potentially sensitive) request details at DEBUG and TRACE level is allowed.",
"defaultValue": false,
"deprecation" : {
"replacement" : "spring.mvc.log-request-details",
"level" : "error"
}
},
{
"name": "spring.mvc.converters.preferred-json-mapper",
"type": "java.lang.String",
"description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment."
},
{
"name": "spring.http.converters.preferred-json-mapper",
"type": "java.lang.String",
"description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment.",
"deprecation" : {
"replacement" : "spring.mvc.converters.preferred-json-mapper",
"level" : "error"
}
},
{
"name": "spring.integration.jdbc.initialize-schema",
"defaultValue": "embedded"
@@ -2356,7 +2434,7 @@
]
},
{
"name": "spring.http.converters.preferred-json-mapper",
"name": "spring.mvc.converters.preferred-json-mapper",
"values": [
{
"value": "gson"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ class HttpMessageConvertersAutoConfigurationTests {
@Test
void gsonCanBePreferred() {
allOptionsRunner().withPropertyValues("spring.http.converters.preferred-json-mapper:gson").run((context) -> {
allOptionsRunner().withPropertyValues("spring.mvc.converters.preferred-json-mapper:gson").run((context) -> {
assertConverterBeanExists(context, GsonHttpMessageConverter.class, "gsonHttpMessageConverter");
assertConverterBeanRegisteredWithHttpMessageConverters(context, GsonHttpMessageConverter.class);
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
@@ -152,7 +152,7 @@ class HttpMessageConvertersAutoConfigurationTests {
@Test
void jsonbCanBePreferred() {
allOptionsRunner().withPropertyValues("spring.http.converters.preferred-json-mapper:jsonb").run((context) -> {
allOptionsRunner().withPropertyValues("spring.mvc.converters.preferred-json-mapper:jsonb").run((context) -> {
assertConverterBeanExists(context, JsonbHttpMessageConverter.class, "jsonbHttpMessageConverter");
assertConverterBeanRegisteredWithHttpMessageConverters(context, JsonbHttpMessageConverter.class);
assertThat(context).doesNotHaveBean(GsonHttpMessageConverter.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.codec.CodecProperties;
import org.springframework.boot.autoconfigure.http.HttpProperties;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.codec.CodecCustomizer;
import org.springframework.context.annotation.Bean;
@@ -59,7 +58,7 @@ class CodecsAutoConfigurationTests {
@Test
void loggingRequestDetailsCustomizerShouldUseHttpProperties() {
this.contextRunner.withPropertyValues("spring.http.log-request-details=true").run((context) -> {
this.contextRunner.withPropertyValues("spring.codec.log-request-details=true").run((context) -> {
CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
CodecConfigurer configurer = new DefaultClientCodecConfigurer();
customizer.customize(configurer);
@@ -72,7 +71,7 @@ class CodecsAutoConfigurationTests {
this.contextRunner.run((context) -> {
Method customizerMethod = ReflectionUtils.findMethod(
CodecsAutoConfiguration.DefaultCodecsConfiguration.class, "defaultCodecCustomizer",
HttpProperties.class, CodecProperties.class);
CodecProperties.class);
Integer order = new TestAnnotationAwareOrderComparator().findOrder(customizerMethod);
assertThat(order).isEqualTo(0);
});

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,49 +69,53 @@ class HttpEncodingAutoConfigurationTests {
@Test
void disableConfiguration() {
load(EmptyConfiguration.class, "spring.http.encoding.enabled:false");
load(EmptyConfiguration.class, "server.servlet.encoding.enabled:false");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(CharacterEncodingFilter.class));
}
@Test
void customConfiguration() {
load(EmptyConfiguration.class, "spring.http.encoding.charset:ISO-8859-15", "spring.http.encoding.force:false");
load(EmptyConfiguration.class, "server.servlet.encoding.charset:ISO-8859-15",
"server.servlet.encoding.force:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "ISO-8859-15", false, false);
}
@Test
void customFilterConfiguration() {
load(FilterConfiguration.class, "spring.http.encoding.charset:ISO-8859-15", "spring.http.encoding.force:false");
load(FilterConfiguration.class, "server.servlet.encoding.charset:ISO-8859-15",
"server.servlet.encoding.force:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "US-ASCII", false, false);
}
@Test
void forceRequest() {
load(EmptyConfiguration.class, "spring.http.encoding.force-request:false");
load(EmptyConfiguration.class, "server.servlet.encoding.force-request:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", false, false);
}
@Test
void forceResponse() {
load(EmptyConfiguration.class, "spring.http.encoding.force-response:true");
load(EmptyConfiguration.class, "server.servlet.encoding.force-response:true");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", true, true);
}
@Test
void forceRequestOverridesForce() {
load(EmptyConfiguration.class, "spring.http.encoding.force:true", "spring.http.encoding.force-request:false");
load(EmptyConfiguration.class, "server.servlet.encoding.force:true",
"server.servlet.encoding.force-request:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", false, true);
}
@Test
void forceResponseOverridesForce() {
load(EmptyConfiguration.class, "spring.http.encoding.force:true", "spring.http.encoding.force-response:false");
load(EmptyConfiguration.class, "server.servlet.encoding.force:true",
"server.servlet.encoding.force-response:false");
CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
assertCharacterEncodingFilter(filter, "UTF-8", true, false);
}
@@ -135,8 +139,8 @@ class HttpEncodingAutoConfigurationTests {
@Test
void customLocaleCharsetMappings() {
load(EmptyConfiguration.class, "spring.http.encoding.mapping.en:UTF-8",
"spring.http.encoding.mapping.fr_FR:UTF-8");
load(EmptyConfiguration.class, "server.servlet.encoding.mapping.en:UTF-8",
"server.servlet.encoding.mapping.fr_FR:UTF-8");
Map<String, WebServerFactoryCustomizer<?>> beans = getWebServerFactoryCustomizerBeans();
assertThat(beans.size()).isEqualTo(1);
assertThat(this.context.getBean(MockServletWebServerFactory.class).getLocaleCharsetMappings().size())