org.zodiac.autoconfigure.server.proxy.ProxyServerConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.server.proxy;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.Optional;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.zodiac.autoconfigure.netty2.NettyServerProperties;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.commons.util.Colls;
@SpringBootConfiguration
@ConditionalOnProperty(name = org.zodiac.server.proxy.constants.ProxyServerSystemPropertiesConstants.SERVER_PROXY_ENABLED, havingValue = "true")
@ConditionalOnClass(value = {org.zodiac.server.proxy.ProxyManager.class, org.zodiac.netty.core.config.NettyServerInfo.class, org.zodiac.server.base.impl.AbstractBaseNettyServer.class})
class ProxyServerConfiguration {
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SERVER_NETTY_PREFIX, ignoreInvalidFields = true)
protected NettyServerHttpProxyProperties nettyServerHttpProxyProperties(
ObjectProvider serverPropertiesProvider,
ObjectProvider multipartPropertiesProvider,
NettyServerProperties nettyServerProperties) {
NettyServerHttpProxyProperties nettyServerHttpProxyProperties =
new NettyServerHttpProxyProperties(nettyServerProperties);
Optional.ofNullable(serverPropertiesProvider.getIfAvailable()).ifPresent(p -> {
nettyServerHttpProxyProperties.getHandler().setEnableSsl(null != p.getSsl() && p.getSsl().isEnabled());
nettyServerHttpProxyProperties.getHttp().getHttp20()
.setEnabled(null != p.getHttp2() && p.getHttp2().isEnabled());
});
Optional.ofNullable(multipartPropertiesProvider.getIfAvailable()).ifPresent(p -> {
nettyServerHttpProxyProperties.getHttp().getServlet().getMultipart().setEnabled(p.getEnabled())
.setFileSizeThreshold(p.getFileSizeThreshold()).setLocation(p.getLocation())
.setMaxFileSize(p.getMaxFileSize()).setMaxRequestSize(p.getMaxFileSize())
.setResolveLazily(p.isResolveLazily());
});
return nettyServerHttpProxyProperties;
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(prefix = org.zodiac.server.proxy.constants.ProxyServerSystemPropertiesConstants.SERVER_PROXY_PREFIX, ignoreInvalidFields = true)
protected NettyServerProxySettingsProperties nettyServerProxySettingsProperties(ObjectProvider