Add config property for http2 by default

This commit is contained in:
Dave Syer
2025-03-03 09:26:06 +00:00
parent 3047c27f9c
commit ebf9caa44d
4 changed files with 42 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
spring.application.name=grpc-tomcat-secure
server.port=9090
server.http2.enabled=true
spring.security.user.name=user
spring.security.user.password=user

View File

@@ -1,6 +1,5 @@
spring.application.name=grpc-tomcat
server.port=9090
server.http2.enabled=true
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
logging.level.org.springframework.security=DEBUG
management.endpoints.web.exposure.include=*

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2024-2024 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
*
* https://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.grpc.autoconfigure.server;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.ClassUtils;
public class ServletEnvironmentPostProcessor implements EnvironmentPostProcessor {
private static final boolean SERVLET_AVAILABLE = ClassUtils.isPresent("io.grpc.servlet.jakarta.GrpcServlet", null);
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (SERVLET_AVAILABLE) {
environment.getPropertySources()
.addFirst(new MapPropertySource("grpc-servlet", Map.of("server.http2.enabled", "true")));
}
}
}

View File

@@ -1,2 +1,5 @@
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer=\
org.springframework.grpc.autoconfigure.server.security.GrpcDisableCsrfHttpConfigurer
org.springframework.grpc.autoconfigure.server.security.GrpcDisableCsrfHttpConfigurer
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.grpc.autoconfigure.server.ServletEnvironmentPostProcessor