Commit 58db841c authored by Brian Clozel's avatar Brian Clozel

Add Http2 configuration properties

This commit adds a new configuration properties class for configuring
HTTP/2 protocol support.
By default, this protocol is disabled as enabling it requires several
manual changes:

* configuring a web server for proper TLS and ALPN support
* configuring a proper SSL certificate

See gh-10043
parent 7f58db7d
...@@ -31,6 +31,7 @@ import java.util.TimeZone; ...@@ -31,6 +31,7 @@ import java.util.TimeZone;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.web.server.Compression; import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.servlet.server.Jsp; import org.springframework.boot.web.servlet.server.Jsp;
import org.springframework.util.Assert; import org.springframework.util.Assert;
...@@ -102,6 +103,9 @@ public class ServerProperties { ...@@ -102,6 +103,9 @@ public class ServerProperties {
@NestedConfigurationProperty @NestedConfigurationProperty
private Compression compression = new Compression(); private Compression compression = new Compression();
@NestedConfigurationProperty
private Http2 http2 = new Http2();
private Servlet servlet = new Servlet(); private Servlet servlet = new Servlet();
private final Tomcat tomcat = new Tomcat(); private final Tomcat tomcat = new Tomcat();
...@@ -190,6 +194,10 @@ public class ServerProperties { ...@@ -190,6 +194,10 @@ public class ServerProperties {
return this.compression; return this.compression;
} }
public Http2 getHttp2() {
return this.http2;
}
public Servlet getServlet() { public Servlet getServlet() {
return this.servlet; return this.servlet;
} }
......
...@@ -55,6 +55,9 @@ public class DefaultReactiveWebServerCustomizer implements ...@@ -55,6 +55,9 @@ public class DefaultReactiveWebServerCustomizer implements
if (this.serverProperties.getCompression() != null) { if (this.serverProperties.getCompression() != null) {
server.setCompression(this.serverProperties.getCompression()); server.setCompression(this.serverProperties.getCompression());
} }
if (this.serverProperties.getHttp2() != null) {
server.setHttp2(this.serverProperties.getHttp2());
}
} }
} }
...@@ -120,6 +120,9 @@ public class DefaultServletWebServerFactoryCustomizer ...@@ -120,6 +120,9 @@ public class DefaultServletWebServerFactoryCustomizer
if (this.serverProperties.getCompression() != null) { if (this.serverProperties.getCompression() != null) {
factory.setCompression(this.serverProperties.getCompression()); factory.setCompression(this.serverProperties.getCompression());
} }
if (this.serverProperties.getHttp2() != null) {
factory.setHttp2(this.serverProperties.getHttp2());
}
factory.setServerHeader(this.serverProperties.getServerHeader()); factory.setServerHeader(this.serverProperties.getServerHeader());
if (factory instanceof TomcatServletWebServerFactory) { if (factory instanceof TomcatServletWebServerFactory) {
TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment,
......
...@@ -165,6 +165,7 @@ content into your application; rather pick only the properties that you need. ...@@ -165,6 +165,7 @@ content into your application; rather pick only the properties that you need.
server.error.include-stacktrace=never # When to include a "stacktrace" attribute. server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
server.error.path=/error # Path of the error controller. server.error.path=/error # Path of the error controller.
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error. server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
server.http2.enabled=true # Enable HTTP/2 support if the current environment supports it.
server.jetty.acceptors= # Number of acceptor threads to use. server.jetty.acceptors= # Number of acceptor threads to use.
server.jetty.accesslog.append=false # Append to log. server.jetty.accesslog.append=false # Append to log.
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log. server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.
......
...@@ -50,6 +50,8 @@ public class AbstractConfigurableWebServerFactory ...@@ -50,6 +50,8 @@ public class AbstractConfigurableWebServerFactory
private SslStoreProvider sslStoreProvider; private SslStoreProvider sslStoreProvider;
private Http2 http2;
private Compression compression; private Compression compression;
private String serverHeader; private String serverHeader;
...@@ -134,6 +136,15 @@ public class AbstractConfigurableWebServerFactory ...@@ -134,6 +136,15 @@ public class AbstractConfigurableWebServerFactory
this.sslStoreProvider = sslStoreProvider; this.sslStoreProvider = sslStoreProvider;
} }
public Http2 getHttp2() {
return this.http2;
}
@Override
public void setHttp2(Http2 http2) {
this.http2 = http2;
}
public Compression getCompression() { public Compression getCompression() {
return this.compression; return this.compression;
} }
......
...@@ -62,6 +62,12 @@ public interface ConfigurableWebServerFactory ...@@ -62,6 +62,12 @@ public interface ConfigurableWebServerFactory
*/ */
void setSslStoreProvider(SslStoreProvider sslStoreProvider); void setSslStoreProvider(SslStoreProvider sslStoreProvider);
/**
* Sets the HTTP/2 configuration that will be applied to the server.
* @param http2 the HTTP/2 configuration
*/
void setHttp2(Http2 http2);
/** /**
* Sets the compression configuration that will be applied to the server's default * Sets the compression configuration that will be applied to the server's default
* connector. * connector.
......
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.web.server;
/**
* Simple server-independent abstraction for HTTP/2 configuration.
*
* @author Brian Clozel
* @since 2.0.0
*/
public class Http2 {
/**
* If HTTP/2 protocol is enabled.
*/
private boolean enabled = false;
public boolean getEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
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