Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,11 @@ public static class Jetty {
*/
private DataSize maxHttpFormPostSize = DataSize.ofBytes(200000);

/**
* Maximum size of the form keys.
*/
private int maxFormKeys = 1000;

/**
* Time that the connection can be idle before it is closed.
*/
Expand Down Expand Up @@ -1180,6 +1185,14 @@ public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
this.maxHttpFormPostSize = maxHttpFormPostSize;
}

public int getMaxFormKeys() {
return maxFormKeys;
}

public void setMaxFormKeys(int maxFormKeys) {
this.maxFormKeys = maxFormKeys;
}

public Duration getConnectionIdleTimeout() {
return this.connectionIdleTimeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.server.AbstractConnector;
Expand Down Expand Up @@ -93,7 +94,11 @@ public void customize(ConfigurableJettyWebServerFactory factory) {
map.from(properties::getMaxHttpFormPostSize)
.asInt(DataSize::toBytes)
.when(this::isPositive)
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
.to((maxHttpFormPostSize) -> customizeServletContextHandler(factory, contextHandler -> contextHandler.setMaxFormContentSize(maxHttpFormPostSize)));
map.from(properties::getMaxFormKeys)
.when(this::isPositive)
.to((maxFormKeys) -> customizeServletContextHandler(factory, contextHandler -> contextHandler.setMaxFormKeys(maxFormKeys)));

map.from(properties::getConnectionIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
map.from(properties::getAccesslog)
.when(ServerProperties.Jetty.Accesslog::isEnabled)
Expand Down Expand Up @@ -122,7 +127,7 @@ private void customizeIdleTimeout(ConfigurableJettyWebServerFactory factory, Dur
});
}

private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) {
private void customizeServletContextHandler(ConfigurableJettyWebServerFactory factory, Consumer<ServletContextHandler> customFunc) {
factory.addServerCustomizers(new JettyServerCustomizer() {

@Override
Expand All @@ -138,7 +143,7 @@ private void setHandlerMaxHttpFormPostSize(List<Handler> handlers) {

private void setHandlerMaxHttpFormPostSize(Handler handler) {
if (handler instanceof ServletContextHandler contextHandler) {
contextHandler.setMaxFormContentSize(maxHttpFormPostSize);
customFunc.accept(contextHandler);
}
else if (handler instanceof Handler.Wrapper wrapper) {
setHandlerMaxHttpFormPostSize(wrapper.getHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ void jettyMaxHttpFormPostSizeMatchesDefault() {
.isEqualTo(((ServletContextHandler) server.getHandler()).getMaxFormContentSize());
}

@Test
void jettyMaxFormKeysMatchesDefault() {
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer();
Server server = jetty.getServer();
assertThat(this.properties.getJetty().getMaxFormKeys())
.isEqualTo(((ServletContextHandler) server.getHandler()).getMaxFormKeys());
}

@Test
void undertowMaxHttpPostSizeMatchesDefault() {
assertThat(this.properties.getUndertow().getMaxHttpPostSize().toBytes())
Expand Down