Commit a64f2699 authored by Andy Wilkinson's avatar Andy Wilkinson

Configure Undertow not to presever path on forward by default

Closes gh-23619
parent 809e2c02
......@@ -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;
}
......
......@@ -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());
}
}
......@@ -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();
}
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment