Merge branch '2.2.x'

Closes gh-21343
This commit is contained in:
Madhura Bhave 2020-05-06 16:00:24 -07:00
commit 01404aa27b
4 changed files with 16 additions and 7 deletions

View File

@ -337,7 +337,7 @@ public class ServerProperties {
* Whether HTTP 1.1 and later location headers generated by a call to sendRedirect * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect
* will use relative or absolute redirects. * will use relative or absolute redirects.
*/ */
private Boolean useRelativeRedirects; private boolean useRelativeRedirects;
/** /**
* Character encoding to use to decode the URI. * Character encoding to use to decode the URI.
@ -532,14 +532,19 @@ public class ServerProperties {
this.redirectContextRoot = redirectContextRoot; this.redirectContextRoot = redirectContextRoot;
} }
public Boolean getUseRelativeRedirects() { public boolean getUseRelativeRedirects() {
return this.useRelativeRedirects; return this.useRelativeRedirects;
} }
public void setUseRelativeRedirects(Boolean useRelativeRedirects) { public void setUseRelativeRedirects(boolean useRelativeRedirects) {
this.useRelativeRedirects = useRelativeRedirects; this.useRelativeRedirects = useRelativeRedirects;
} }
@Deprecated
public void setUseRelativeRedirects(Boolean useRelativeRedirects) {
this.useRelativeRedirects = (useRelativeRedirects != null) ? useRelativeRedirects : false;
}
public Charset getUriEncoding() { public Charset getUriEncoding() {
return this.uriEncoding; return this.uriEncoding;
} }

View File

@ -54,9 +54,7 @@ public class TomcatServletWebServerFactoryCustomizer
if (tomcatProperties.getRedirectContextRoot() != null) { if (tomcatProperties.getRedirectContextRoot() != null) {
customizeRedirectContextRoot(factory, tomcatProperties.getRedirectContextRoot()); customizeRedirectContextRoot(factory, tomcatProperties.getRedirectContextRoot());
} }
if (tomcatProperties.getUseRelativeRedirects() != null) { customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects());
}
factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled()); factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled());
} }

View File

@ -126,6 +126,7 @@ class ServerPropertiesTests {
map.put("server.tomcat.background-processor-delay", "10"); map.put("server.tomcat.background-processor-delay", "10");
map.put("server.tomcat.relaxed-path-chars", "|,<"); map.put("server.tomcat.relaxed-path-chars", "|,<");
map.put("server.tomcat.relaxed-query-chars", "^ , | "); map.put("server.tomcat.relaxed-query-chars", "^ , | ");
map.put("server.tomcat.use-relative-redirects", "true");
bind(map); bind(map);
ServerProperties.Tomcat tomcat = this.properties.getTomcat(); ServerProperties.Tomcat tomcat = this.properties.getTomcat();
Accesslog accesslog = tomcat.getAccesslog(); Accesslog accesslog = tomcat.getAccesslog();
@ -147,6 +148,7 @@ class ServerPropertiesTests {
assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10); assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10);
assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<'); assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<');
assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|'); assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|');
assertThat(tomcat.getUseRelativeRedirects()).isTrue();
} }
@Test @Test
@ -443,6 +445,11 @@ class ServerPropertiesTests {
.isEqualTo(new RemoteIpValve().getInternalProxies()); .isEqualTo(new RemoteIpValve().getInternalProxies());
} }
@Test
void tomcatUseRelativeRedirectsDefaultsToFalse() {
assertThat(this.properties.getTomcat().getUseRelativeRedirects()).isFalse();
}
@Test @Test
void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception { void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0); JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);

View File

@ -214,7 +214,6 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
: ClassUtils.getDefaultClassLoader()); : ClassUtils.getDefaultClassLoader());
resetDefaultLocaleMapping(context); resetDefaultLocaleMapping(context);
addLocaleMappings(context); addLocaleMappings(context);
context.setUseRelativeRedirects(false);
try { try {
context.setCreateUploadTargets(true); context.setCreateUploadTargets(true);
} }