diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 48aee2b6549..12773a79ea9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -337,7 +337,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. @@ -532,14 +532,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 Charset getUriEncoding() { return this.uriEncoding; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java index 8e4b320cfe6..3b4184f4616 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java @@ -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()); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index f86f864127f..a4d3d3137a2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -126,6 +126,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(); @@ -147,6 +148,7 @@ class ServerPropertiesTests { assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10); assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<'); assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|'); + assertThat(tomcat.getUseRelativeRedirects()).isTrue(); } @Test @@ -443,6 +445,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); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index acb52c87541..7cc4097635e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -214,7 +214,6 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto : ClassUtils.getDefaultClassLoader()); resetDefaultLocaleMapping(context); addLocaleMappings(context); - context.setUseRelativeRedirects(false); try { context.setCreateUploadTargets(true); }