Skip to content

Commit 58db841

Browse files
committed
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
1 parent 7f58db7 commit 58db841

File tree

7 files changed

+71
-0
lines changed

7 files changed

+71
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.boot.context.properties.ConfigurationProperties;
3232
import org.springframework.boot.context.properties.NestedConfigurationProperty;
3333
import org.springframework.boot.web.server.Compression;
34+
import org.springframework.boot.web.server.Http2;
3435
import org.springframework.boot.web.server.Ssl;
3536
import org.springframework.boot.web.servlet.server.Jsp;
3637
import org.springframework.util.Assert;
@@ -102,6 +103,9 @@ public class ServerProperties {
102103
@NestedConfigurationProperty
103104
private Compression compression = new Compression();
104105

106+
@NestedConfigurationProperty
107+
private Http2 http2 = new Http2();
108+
105109
private Servlet servlet = new Servlet();
106110

107111
private final Tomcat tomcat = new Tomcat();
@@ -190,6 +194,10 @@ public Compression getCompression() {
190194
return this.compression;
191195
}
192196

197+
public Http2 getHttp2() {
198+
return this.http2;
199+
}
200+
193201
public Servlet getServlet() {
194202
return this.servlet;
195203
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/DefaultReactiveWebServerCustomizer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void customize(ConfigurableReactiveWebServerFactory server) {
5555
if (this.serverProperties.getCompression() != null) {
5656
server.setCompression(this.serverProperties.getCompression());
5757
}
58+
if (this.serverProperties.getHttp2() != null) {
59+
server.setHttp2(this.serverProperties.getHttp2());
60+
}
5861
}
5962

6063
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public void customize(ConfigurableServletWebServerFactory factory) {
120120
if (this.serverProperties.getCompression() != null) {
121121
factory.setCompression(this.serverProperties.getCompression());
122122
}
123+
if (this.serverProperties.getHttp2() != null) {
124+
factory.setHttp2(this.serverProperties.getHttp2());
125+
}
123126
factory.setServerHeader(this.serverProperties.getServerHeader());
124127
if (factory instanceof TomcatServletWebServerFactory) {
125128
TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment,

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ content into your application; rather pick only the properties that you need.
165165
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
166166
server.error.path=/error # Path of the error controller.
167167
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
168+
server.http2.enabled=true # Enable HTTP/2 support if the current environment supports it.
168169
server.jetty.acceptors= # Number of acceptor threads to use.
169170
server.jetty.accesslog.append=false # Append to log.
170171
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class AbstractConfigurableWebServerFactory
5050

5151
private SslStoreProvider sslStoreProvider;
5252

53+
private Http2 http2;
54+
5355
private Compression compression;
5456

5557
private String serverHeader;
@@ -134,6 +136,15 @@ public void setSslStoreProvider(SslStoreProvider sslStoreProvider) {
134136
this.sslStoreProvider = sslStoreProvider;
135137
}
136138

139+
public Http2 getHttp2() {
140+
return this.http2;
141+
}
142+
143+
@Override
144+
public void setHttp2(Http2 http2) {
145+
this.http2 = http2;
146+
}
147+
137148
public Compression getCompression() {
138149
return this.compression;
139150
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public interface ConfigurableWebServerFactory
6262
*/
6363
void setSslStoreProvider(SslStoreProvider sslStoreProvider);
6464

65+
/**
66+
* Sets the HTTP/2 configuration that will be applied to the server.
67+
* @param http2 the HTTP/2 configuration
68+
*/
69+
void setHttp2(Http2 http2);
70+
6571
/**
6672
* Sets the compression configuration that will be applied to the server's default
6773
* connector.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.web.server;
18+
19+
/**
20+
* Simple server-independent abstraction for HTTP/2 configuration.
21+
*
22+
* @author Brian Clozel
23+
* @since 2.0.0
24+
*/
25+
public class Http2 {
26+
27+
/**
28+
* If HTTP/2 protocol is enabled.
29+
*/
30+
private boolean enabled = false;
31+
32+
public boolean getEnabled() {
33+
return this.enabled;
34+
}
35+
36+
public void setEnabled(boolean enabled) {
37+
this.enabled = enabled;
38+
}
39+
}

0 commit comments

Comments
 (0)