Skip to content
Closed
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 @@ -19,6 +19,7 @@
import java.io.File;
import java.net.InetAddress;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,6 +31,8 @@
import javax.servlet.SessionTrackingMode;
import javax.validation.constraints.NotNull;

import io.undertow.Undertow;
import io.undertow.UndertowOptions;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.valves.AccessLogValve;
Expand All @@ -50,12 +53,14 @@
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;
import org.springframework.util.StringUtils;
import org.xnio.Option;

/**
* {@link ConfigurationProperties} for a web server (e.g. port and path settings). Will be
Expand Down Expand Up @@ -847,6 +852,11 @@ public static class Undertow {

private final Accesslog accesslog = new Accesslog();

/**
*
*/
private ServerOption serverOption;

public Integer getBufferSize() {
return this.bufferSize;
}
Expand Down Expand Up @@ -954,6 +964,14 @@ public void setAccessLogDir(File accessLogDir) {
getAccesslog().setDir(accessLogDir);
}

public ServerOption getServerOption() {
return this.serverOption;
}

public void setServerOption(ServerOption serverOption) {
this.serverOption = serverOption;
}

void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) {
factory.setBufferSize(this.bufferSize);
factory.setBuffersPerRegion(this.buffersPerRegion);
Expand All @@ -963,6 +981,34 @@ void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) {
factory.setAccessLogDirectory(this.accesslog.dir);
factory.setAccessLogPattern(this.accesslog.pattern);
factory.setAccessLogEnabled(this.accesslog.enabled);

if (this.serverOption != null) {
UndertowBuilderCustomizer customizer = new UndertowBuilderCustomizer() {
@Override
public void customize(io.undertow.Undertow.Builder builder) {
builder.setServerOption(serverOption.getOption(), false);
}
};

factory.setBuilderCustomizers(Arrays.asList(customizer));
}
}

public enum ServerOption {

SPDY(UndertowOptions.ENABLE_SPDY),
HTTP2(UndertowOptions.ENABLE_HTTP2);

private Option<Boolean> option;

ServerOption(Option<Boolean> option) {
this.option = option;
}

public Option<Boolean> getOption() {
return this.option;
}

}

public static class Accesslog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
Expand Down Expand Up @@ -313,6 +315,18 @@ public void customTomcatRemoteIpValve() throws Exception {
assertEquals("192.168.0.1", remoteIpValve.getInternalProxies());
}

@Test
public void enableUndertowHttp2() {
Map<String, String> map = new HashMap<String, String>();
map.put("server.undertow.server-option", "HTTP2");
bindProperties(map);

UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
this.properties.customize(container);

assertEquals(1, container.getBuilderCustomizers().size());
}

private void bindProperties(Map<String, String> map) {
new RelaxedDataBinder(this.properties, "server").bind(new MutablePropertyValues(
map));
Expand Down