|
|
@ -17,6 +17,8 @@
|
|
|
|
package org.springframework.boot.autoconfigure.web.embedded;
|
|
|
|
package org.springframework.boot.autoconfigure.web.embedded;
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelOption;
|
|
|
|
import io.netty.channel.ChannelOption;
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +29,6 @@ import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
|
|
|
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
|
|
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.util.unit.DataSize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Customization for Netty-specific features.
|
|
|
|
* Customization for Netty-specific features.
|
|
|
@ -58,11 +59,16 @@ public class NettyWebServerFactoryCustomizer
|
|
|
|
public void customize(NettyReactiveWebServerFactory factory) {
|
|
|
|
public void customize(NettyReactiveWebServerFactory factory) {
|
|
|
|
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
|
|
|
|
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
|
|
|
|
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
propertyMapper.from(this.serverProperties::getMaxHttpHeaderSize)
|
|
|
|
|
|
|
|
.to((maxHttpRequestHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpRequestHeaderSize));
|
|
|
|
|
|
|
|
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
|
|
|
|
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
|
|
|
|
propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull()
|
|
|
|
propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull()
|
|
|
|
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
|
|
|
|
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
|
|
|
|
|
|
|
|
if (Stream
|
|
|
|
|
|
|
|
.of(this.serverProperties.getMaxHttpHeaderSize(), nettyProperties.getH2cMaxContentLength(),
|
|
|
|
|
|
|
|
nettyProperties.getMaxChunkSize(), nettyProperties.getMaxInitialLineLength(),
|
|
|
|
|
|
|
|
nettyProperties.getValidateHeaders(), nettyProperties.getInitialBufferSize())
|
|
|
|
|
|
|
|
.anyMatch(Objects::nonNull)) {
|
|
|
|
|
|
|
|
customizeRequestDecoder(factory, propertyMapper);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean getOrDeduceUseForwardHeaders() {
|
|
|
|
private boolean getOrDeduceUseForwardHeaders() {
|
|
|
@ -73,9 +79,26 @@ public class NettyWebServerFactoryCustomizer
|
|
|
|
return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
|
|
|
return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void customizeMaxHttpHeaderSize(NettyReactiveWebServerFactory factory, DataSize maxHttpHeaderSize) {
|
|
|
|
private void customizeRequestDecoder(NettyReactiveWebServerFactory factory, PropertyMapper propertyMapper) {
|
|
|
|
factory.addServerCustomizers((httpServer) -> httpServer.httpRequestDecoder(
|
|
|
|
factory.addServerCustomizers((httpServer) -> httpServer.httpRequestDecoder((httpRequestDecoderSpec) -> {
|
|
|
|
(httpRequestDecoderSpec) -> httpRequestDecoderSpec.maxHeaderSize((int) maxHttpHeaderSize.toBytes())));
|
|
|
|
propertyMapper.from(this.serverProperties.getMaxHttpHeaderSize()).whenNonNull()
|
|
|
|
|
|
|
|
.to((maxHttpRequestHeader) -> httpRequestDecoderSpec
|
|
|
|
|
|
|
|
.maxHeaderSize((int) maxHttpRequestHeader.toBytes()));
|
|
|
|
|
|
|
|
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
|
|
|
|
|
|
|
|
propertyMapper.from(nettyProperties.getMaxChunkSize()).whenNonNull()
|
|
|
|
|
|
|
|
.to((maxChunkSize) -> httpRequestDecoderSpec.maxChunkSize((int) maxChunkSize.toBytes()));
|
|
|
|
|
|
|
|
propertyMapper.from(nettyProperties.getMaxInitialLineLength()).whenNonNull()
|
|
|
|
|
|
|
|
.to((maxInitialLineLength) -> httpRequestDecoderSpec
|
|
|
|
|
|
|
|
.maxInitialLineLength((int) maxInitialLineLength.toBytes()));
|
|
|
|
|
|
|
|
propertyMapper.from(nettyProperties.getH2cMaxContentLength()).whenNonNull()
|
|
|
|
|
|
|
|
.to((h2cMaxContentLength) -> httpRequestDecoderSpec
|
|
|
|
|
|
|
|
.h2cMaxContentLength((int) h2cMaxContentLength.toBytes()));
|
|
|
|
|
|
|
|
propertyMapper.from(nettyProperties.getInitialBufferSize()).whenNonNull().to(
|
|
|
|
|
|
|
|
(initialBufferSize) -> httpRequestDecoderSpec.initialBufferSize((int) initialBufferSize.toBytes()));
|
|
|
|
|
|
|
|
propertyMapper.from(nettyProperties.getValidateHeaders()).whenNonNull()
|
|
|
|
|
|
|
|
.to(httpRequestDecoderSpec::validateHeaders);
|
|
|
|
|
|
|
|
return httpRequestDecoderSpec;
|
|
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void customizeConnectionTimeout(NettyReactiveWebServerFactory factory, Duration connectionTimeout) {
|
|
|
|
private void customizeConnectionTimeout(NettyReactiveWebServerFactory factory, Duration connectionTimeout) {
|
|
|
|