Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added additional jetty configuration options #6043

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -325,6 +325,7 @@ private static ServerConnector createConnector(Server server, JettyConfig config
httpConfig.addCustomizer(new SecureRequestCustomizer(config.sniHostCheck()));
final HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpConfig);
h2.setRateControlFactory(new RateControl.Factory() {});
config.maxConcurrentStreams().ifPresent(h2::setMaxConcurrentStreams);

final ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http11 != null ? http11.getProtocol() : h2.getProtocol());
Expand All @@ -345,6 +346,8 @@ private static ServerConnector createConnector(Server server, JettyConfig config
} else {
final HTTP2CServerConnectionFactory h2c = new HTTP2CServerConnectionFactory(httpConfig);
h2c.setRateControlFactory(new RateControl.Factory() {});
config.maxConcurrentStreams().ifPresent(h2c::setMaxConcurrentStreams);

if (http11 != null) {
serverConnector = new ServerConnector(server, http11, h2c);
} else {
Expand All @@ -353,6 +356,7 @@ private static ServerConnector createConnector(Server server, JettyConfig config
}
config.host().ifPresent(serverConnector::setHost);
serverConnector.setPort(config.port());
config.maxHeaderRequestSize().ifPresent(httpConfig::setRequestHeaderSize);

// Give connections extra time to shutdown, since we have an explicit server shutdown
serverConnector.setShutdownIdleTimeout(serverConnector.getIdleTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.immutables.value.Value.Style;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;

/**
Expand All @@ -29,6 +31,8 @@ public abstract class JettyConfig implements ServerConfig {
public static final String HTTP_STREAM_TIMEOUT = "http2.stream.idleTimeoutMs";
public static final String HTTP_COMPRESSION = "http.compression";
public static final String SNI_HOST_CHECK = "https.sniHostCheck";
public static final String MAX_CONCURRENT_STREAMS = "http2.maxConcurrentStreams";
public static final String MAX_HEADER_REQUEST_SIZE = "http.maxHeaderRequestSize";

/**
* Values to indicate what kind of websocket support should be offered.
Expand Down Expand Up @@ -93,6 +97,8 @@ public static Builder buildFromConfig(Configuration config) {
String httpCompression = config.getStringWithDefault(HTTP_COMPRESSION, null);
String sniHostCheck = config.getStringWithDefault(SNI_HOST_CHECK, null);
String h2StreamIdleTimeout = config.getStringWithDefault(HTTP_STREAM_TIMEOUT, null);
String h2MaxConcurrentStreams = config.getStringWithDefault(MAX_CONCURRENT_STREAMS, null);
String maxHeaderRequestSize = config.getStringWithDefault(MAX_HEADER_REQUEST_SIZE, null);
if (httpWebsockets != null) {
switch (httpWebsockets.toLowerCase()) {
case "true":// backwards compatible
Expand Down Expand Up @@ -122,6 +128,12 @@ public static Builder buildFromConfig(Configuration config) {
if (sniHostCheck != null) {
builder.sniHostCheck(Boolean.parseBoolean(sniHostCheck));
}
if (h2MaxConcurrentStreams != null) {
builder.maxConcurrentStreams(Integer.parseInt(h2MaxConcurrentStreams));
}
if (maxHeaderRequestSize != null) {
builder.maxHeaderRequestSize(Integer.parseInt(maxHeaderRequestSize));
}
return builder;
}

Expand Down Expand Up @@ -212,6 +224,16 @@ public final boolean httpCompressionOrDefault() {
return httpCompression == null || httpCompression;
}

/**
* Value is in bytes. If unset, uses Jetty's default (presently 8192).
*/
public abstract OptionalInt maxHeaderRequestSize();

/**
* If unset, uses Jetty's default (presently 128). Only applies to http2 connections.
*/
public abstract OptionalInt maxConcurrentStreams();

public interface Builder extends ServerConfig.Builder<JettyConfig, Builder> {

Builder websockets(WebsocketsSupport websockets);
Expand All @@ -223,5 +245,9 @@ public interface Builder extends ServerConfig.Builder<JettyConfig, Builder> {
Builder http2StreamIdleTimeout(long timeoutInMillis);

Builder sniHostCheck(boolean sniHostCheck);

Builder maxHeaderRequestSize(int maxHeaderRequestSize);

Builder maxConcurrentStreams(int maxConcurrentStreams);
}
}