Skip to content

Commit 01404aa

Browse files
committed
Merge branch '2.2.x'
Closes gh-21343
2 parents be7fe85 + f29bce6 commit 01404aa

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public static class Tomcat {
337337
* Whether HTTP 1.1 and later location headers generated by a call to sendRedirect
338338
* will use relative or absolute redirects.
339339
*/
340-
private Boolean useRelativeRedirects;
340+
private boolean useRelativeRedirects;
341341

342342
/**
343343
* Character encoding to use to decode the URI.
@@ -532,14 +532,19 @@ public void setRedirectContextRoot(Boolean redirectContextRoot) {
532532
this.redirectContextRoot = redirectContextRoot;
533533
}
534534

535-
public Boolean getUseRelativeRedirects() {
535+
public boolean getUseRelativeRedirects() {
536536
return this.useRelativeRedirects;
537537
}
538538

539-
public void setUseRelativeRedirects(Boolean useRelativeRedirects) {
539+
public void setUseRelativeRedirects(boolean useRelativeRedirects) {
540540
this.useRelativeRedirects = useRelativeRedirects;
541541
}
542542

543+
@Deprecated
544+
public void setUseRelativeRedirects(Boolean useRelativeRedirects) {
545+
this.useRelativeRedirects = (useRelativeRedirects != null) ? useRelativeRedirects : false;
546+
}
547+
543548
public Charset getUriEncoding() {
544549
return this.uriEncoding;
545550
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public void customize(TomcatServletWebServerFactory factory) {
5454
if (tomcatProperties.getRedirectContextRoot() != null) {
5555
customizeRedirectContextRoot(factory, tomcatProperties.getRedirectContextRoot());
5656
}
57-
if (tomcatProperties.getUseRelativeRedirects() != null) {
58-
customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
59-
}
57+
customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
6058
factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled());
6159
}
6260

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void testTomcatBinding() {
126126
map.put("server.tomcat.background-processor-delay", "10");
127127
map.put("server.tomcat.relaxed-path-chars", "|,<");
128128
map.put("server.tomcat.relaxed-query-chars", "^ , | ");
129+
map.put("server.tomcat.use-relative-redirects", "true");
129130
bind(map);
130131
ServerProperties.Tomcat tomcat = this.properties.getTomcat();
131132
Accesslog accesslog = tomcat.getAccesslog();
@@ -147,6 +148,7 @@ void testTomcatBinding() {
147148
assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10);
148149
assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<');
149150
assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|');
151+
assertThat(tomcat.getUseRelativeRedirects()).isTrue();
150152
}
151153

152154
@Test
@@ -443,6 +445,11 @@ void tomcatInternalProxiesMatchesDefault() {
443445
.isEqualTo(new RemoteIpValve().getInternalProxies());
444446
}
445447

448+
@Test
449+
void tomcatUseRelativeRedirectsDefaultsToFalse() {
450+
assertThat(this.properties.getTomcat().getUseRelativeRedirects()).isFalse();
451+
}
452+
446453
@Test
447454
void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
448455
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ protected void prepareContext(Host host, ServletContextInitializer[] initializer
214214
: ClassUtils.getDefaultClassLoader());
215215
resetDefaultLocaleMapping(context);
216216
addLocaleMappings(context);
217-
context.setUseRelativeRedirects(false);
218217
try {
219218
context.setCreateUploadTargets(true);
220219
}

0 commit comments

Comments
 (0)