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
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.TimeZone;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
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.servlet.server.Jsp;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -102,6 +103,9 @@ public class ServerProperties {
|
||||
@NestedConfigurationProperty
|
||||
private Compression compression = new Compression();
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private Http2 http2 = new Http2();
|
||||
|
||||
private Servlet servlet = new Servlet();
|
||||
|
||||
private final Tomcat tomcat = new Tomcat();
|
||||
@@ -190,6 +194,10 @@ public class ServerProperties {
|
||||
return this.compression;
|
||||
}
|
||||
|
||||
public Http2 getHttp2() {
|
||||
return this.http2;
|
||||
}
|
||||
|
||||
public Servlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ public class DefaultReactiveWebServerCustomizer implements
|
||||
if (this.serverProperties.getCompression() != null) {
|
||||
server.setCompression(this.serverProperties.getCompression());
|
||||
}
|
||||
if (this.serverProperties.getHttp2() != null) {
|
||||
server.setHttp2(this.serverProperties.getHttp2());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +120,9 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
if (this.serverProperties.getCompression() != null) {
|
||||
factory.setCompression(this.serverProperties.getCompression());
|
||||
}
|
||||
if (this.serverProperties.getHttp2() != null) {
|
||||
factory.setHttp2(this.serverProperties.getHttp2());
|
||||
}
|
||||
factory.setServerHeader(this.serverProperties.getServerHeader());
|
||||
if (factory instanceof TomcatServletWebServerFactory) {
|
||||
TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment,
|
||||
|
||||
@@ -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.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.http2.enabled=true # Enable HTTP/2 support if the current environment supports it.
|
||||
server.jetty.acceptors= # Number of acceptor threads to use.
|
||||
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.
|
||||
|
||||
@@ -50,6 +50,8 @@ public class AbstractConfigurableWebServerFactory
|
||||
|
||||
private SslStoreProvider sslStoreProvider;
|
||||
|
||||
private Http2 http2;
|
||||
|
||||
private Compression compression;
|
||||
|
||||
private String serverHeader;
|
||||
@@ -134,6 +136,15 @@ public class AbstractConfigurableWebServerFactory
|
||||
this.sslStoreProvider = sslStoreProvider;
|
||||
}
|
||||
|
||||
public Http2 getHttp2() {
|
||||
return this.http2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHttp2(Http2 http2) {
|
||||
this.http2 = http2;
|
||||
}
|
||||
|
||||
public Compression getCompression() {
|
||||
return this.compression;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ public interface ConfigurableWebServerFactory
|
||||
*/
|
||||
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
|
||||
* connector.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user