Skip to content

Commit ebf9caa

Browse files
committed
Add config property for http2 by default
1 parent 3047c27 commit ebf9caa

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
spring.application.name=grpc-tomcat-secure
22
server.port=9090
3-
server.http2.enabled=true
43
spring.security.user.name=user
54
spring.security.user.password=user
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
spring.application.name=grpc-tomcat
22
server.port=9090
3-
server.http2.enabled=true
43
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
54
logging.level.org.springframework.security=DEBUG
65
management.endpoints.web.exposure.include=*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024-2024 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+
* https://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+
package org.springframework.grpc.autoconfigure.server;
17+
18+
import java.util.Map;
19+
20+
import org.springframework.boot.SpringApplication;
21+
import org.springframework.boot.env.EnvironmentPostProcessor;
22+
import org.springframework.core.env.ConfigurableEnvironment;
23+
import org.springframework.core.env.MapPropertySource;
24+
import org.springframework.util.ClassUtils;
25+
26+
public class ServletEnvironmentPostProcessor implements EnvironmentPostProcessor {
27+
28+
private static final boolean SERVLET_AVAILABLE = ClassUtils.isPresent("io.grpc.servlet.jakarta.GrpcServlet", null);
29+
30+
@Override
31+
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
32+
if (SERVLET_AVAILABLE) {
33+
environment.getPropertySources()
34+
.addFirst(new MapPropertySource("grpc-servlet", Map.of("server.http2.enabled", "true")));
35+
}
36+
}
37+
38+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer=\
2-
org.springframework.grpc.autoconfigure.server.security.GrpcDisableCsrfHttpConfigurer
2+
org.springframework.grpc.autoconfigure.server.security.GrpcDisableCsrfHttpConfigurer
3+
4+
org.springframework.boot.env.EnvironmentPostProcessor=\
5+
org.springframework.grpc.autoconfigure.server.ServletEnvironmentPostProcessor

0 commit comments

Comments
 (0)