Configure Undertow not to presever path on forward by default

Closes gh-23619
This commit is contained in:
Andy Wilkinson
2020-10-13 19:02:51 +01:00
parent 809e2c023f
commit a64f2699cc
4 changed files with 47 additions and 0 deletions

View File

@@ -1548,6 +1548,11 @@ public class ServerProperties {
*/
private Duration noRequestTimeout;
/**
* Whether to preserve the path of a request when it is forwarded.
*/
private boolean preservePathOnForward = false;
private final Accesslog accesslog = new Accesslog();
/**
@@ -1675,6 +1680,14 @@ public class ServerProperties {
this.noRequestTimeout = noRequestTimeout;
}
public boolean isPreservePathOnForward() {
return this.preservePathOnForward;
}
public void setPreservePathOnForward(boolean preservePathOnForward) {
this.preservePathOnForward = preservePathOnForward;
}
public Accesslog getAccesslog() {
return this.accesslog;
}

View File

@@ -39,6 +39,7 @@ public class UndertowServletWebServerFactoryCustomizer
@Override
public void customize(UndertowServletWebServerFactory factory) {
factory.setEagerInitFilters(this.serverProperties.getUndertow().isEagerFilterInit());
factory.setPreservePathOnForward(this.serverProperties.getUndertow().isPreservePathOnForward());
}
}

View File

@@ -40,4 +40,14 @@ class UndertowServletWebServerFactoryCustomizerTests {
assertThat(factory.isEagerInitFilters()).isFalse();
}
@Test
void preservePathOnForwardCanBeEnabled() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory(0);
assertThat(factory.isPreservePathOnForward()).isFalse();
ServerProperties serverProperties = new ServerProperties();
serverProperties.getUndertow().setPreservePathOnForward(true);
new UndertowServletWebServerFactoryCustomizer(serverProperties).customize(factory);
assertThat(factory.isPreservePathOnForward()).isTrue();
}
}

View File

@@ -93,6 +93,8 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
private boolean eagerInitFilters = true;
private boolean preservePathOnForward = false;
/**
* Create a new {@link UndertowServletWebServerFactory} instance.
*/
@@ -261,6 +263,26 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
this.eagerInitFilters = eagerInitFilters;
}
/**
* Return where the request path should be preserved on forward.
* @return {@code true} if the path should be preserved when a request is forwarded,
* otherwise {@code false}.
* @since 2.4.0
*/
public boolean isPreservePathOnForward() {
return this.preservePathOnForward;
}
/**
* Set whether the request path should be preserved on forward.
* @param preservePathOnForward {@code true} if the path should be preserved when a
* request is forwarded, otherwise {@code false}.
* @since 2.4.0
*/
public void setPreservePathOnForward(boolean preservePathOnForward) {
this.preservePathOnForward = preservePathOnForward;
}
@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
Builder builder = this.delegate.createBuilder(this);
@@ -283,6 +305,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
deployment.setResourceManager(getDocumentRootResourceManager());
deployment.setTempDir(createTempDir("undertow"));
deployment.setEagerFilterInit(this.eagerInitFilters);
deployment.setPreservePathOnForward(this.preservePathOnForward);
configureMimeMappings(deployment);
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
customizer.customize(deployment);