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 7fc84695c0..d3a548c650 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 @@ -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; } 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 8e4b320cfe..3b4184f461 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 17b82914c9..c62c0e81f7 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 @@ -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); 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 109287008f..3c6fbedf29 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); }