Harmonize default for server.tomcat.use-relative-redirects
Prior to this commit, the property was a Boolean with a null default. If it was explicitly set by the user, a context customizer would use that value to set it on the context. However, if it was not set, the default wouldn't be tomcat's default but `false` because it was explicitly set to `false` in `TomcatServletWebServerFactory`. This commit defaults the property itself to `false` so that the default is more obvious to the user. Fixes gh-20796
This commit is contained in:
parent
386d678d99
commit
f29bce657e
|
|
@ -380,7 +380,7 @@ public class ServerProperties {
|
|||
* Whether HTTP 1.1 and later location headers generated by a call to sendRedirect
|
||||
* will use relative or absolute redirects.
|
||||
*/
|
||||
private Boolean useRelativeRedirects;
|
||||
private boolean useRelativeRedirects;
|
||||
|
||||
/**
|
||||
* Character encoding to use to decode the URI.
|
||||
|
|
@ -537,14 +537,19 @@ public class ServerProperties {
|
|||
this.redirectContextRoot = redirectContextRoot;
|
||||
}
|
||||
|
||||
public Boolean getUseRelativeRedirects() {
|
||||
public boolean getUseRelativeRedirects() {
|
||||
return this.useRelativeRedirects;
|
||||
}
|
||||
|
||||
public void setUseRelativeRedirects(Boolean useRelativeRedirects) {
|
||||
public void setUseRelativeRedirects(boolean useRelativeRedirects) {
|
||||
this.useRelativeRedirects = useRelativeRedirects;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setUseRelativeRedirects(Boolean useRelativeRedirects) {
|
||||
this.useRelativeRedirects = (useRelativeRedirects != null) ? useRelativeRedirects : false;
|
||||
}
|
||||
|
||||
public String getRemoteIpHeader() {
|
||||
return this.remoteIpHeader;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,7 @@ public class TomcatServletWebServerFactoryCustomizer
|
|||
if (tomcatProperties.getRedirectContextRoot() != null) {
|
||||
customizeRedirectContextRoot(factory, tomcatProperties.getRedirectContextRoot());
|
||||
}
|
||||
if (tomcatProperties.getUseRelativeRedirects() != null) {
|
||||
customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
|
||||
}
|
||||
customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
|
||||
factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ class ServerPropertiesTests {
|
|||
map.put("server.tomcat.background-processor-delay", "10");
|
||||
map.put("server.tomcat.relaxed-path-chars", "|,<");
|
||||
map.put("server.tomcat.relaxed-query-chars", "^ , | ");
|
||||
map.put("server.tomcat.use-relative-redirects", "true");
|
||||
bind(map);
|
||||
ServerProperties.Tomcat tomcat = this.properties.getTomcat();
|
||||
Accesslog accesslog = tomcat.getAccesslog();
|
||||
|
|
@ -152,6 +153,7 @@ class ServerPropertiesTests {
|
|||
assertThat(tomcat.getBackgroundProcessorDelay()).isEqualTo(Duration.ofSeconds(10));
|
||||
assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<');
|
||||
assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|');
|
||||
assertThat(tomcat.getUseRelativeRedirects()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -347,6 +349,11 @@ class ServerPropertiesTests {
|
|||
.isEqualTo(new RemoteIpValve().getInternalProxies());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tomcatUseRelativeRedirectsDefaultsToFalse() {
|
||||
assertThat(this.properties.getTomcat().getUseRelativeRedirects()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
|
||||
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
|
||||
|
|
|
|||
|
|
@ -214,7 +214,6 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
|
|||
: ClassUtils.getDefaultClassLoader());
|
||||
resetDefaultLocaleMapping(context);
|
||||
addLocaleMappings(context);
|
||||
context.setUseRelativeRedirects(false);
|
||||
try {
|
||||
context.setCreateUploadTargets(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue