Remove duplicate code in NettyWebServerFactoryCustomizer

Since the PropertyMapper's alwaysApplyingWhenNonNull() has already been
called, the subsequent whenNonNull() is unnecessary.

See gh-37434
This commit is contained in:
shin-mallang 2023-09-16 05:22:32 +09:00 committed by Moritz Halbritter
parent 578b4643ac
commit 8eac7a91f6
1 changed files with 1 additions and 8 deletions

View File

@ -65,7 +65,6 @@ public class NettyWebServerFactoryCustomizer
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests)); .to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
if (this.serverProperties.getHttp2() != null && this.serverProperties.getHttp2().isEnabled()) { if (this.serverProperties.getHttp2() != null && this.serverProperties.getHttp2().isEnabled()) {
map.from(this.serverProperties.getMaxHttpRequestHeaderSize()) map.from(this.serverProperties.getMaxHttpRequestHeaderSize())
.whenNonNull()
.to((size) -> customizeHttp2MaxHeaderSize(factory, size.toBytes())); .to((size) -> customizeHttp2MaxHeaderSize(factory, size.toBytes()));
} }
customizeRequestDecoder(factory, map); customizeRequestDecoder(factory, map);
@ -87,24 +86,18 @@ public class NettyWebServerFactoryCustomizer
private void customizeRequestDecoder(NettyReactiveWebServerFactory factory, PropertyMapper propertyMapper) { private void customizeRequestDecoder(NettyReactiveWebServerFactory factory, PropertyMapper propertyMapper) {
factory.addServerCustomizers((httpServer) -> httpServer.httpRequestDecoder((httpRequestDecoderSpec) -> { factory.addServerCustomizers((httpServer) -> httpServer.httpRequestDecoder((httpRequestDecoderSpec) -> {
propertyMapper.from(this.serverProperties.getMaxHttpRequestHeaderSize()) propertyMapper.from(this.serverProperties.getMaxHttpRequestHeaderSize())
.whenNonNull()
.to((maxHttpRequestHeader) -> httpRequestDecoderSpec .to((maxHttpRequestHeader) -> httpRequestDecoderSpec
.maxHeaderSize((int) maxHttpRequestHeader.toBytes())); .maxHeaderSize((int) maxHttpRequestHeader.toBytes()));
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty(); ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
propertyMapper.from(nettyProperties.getMaxInitialLineLength()) propertyMapper.from(nettyProperties.getMaxInitialLineLength())
.whenNonNull()
.to((maxInitialLineLength) -> httpRequestDecoderSpec .to((maxInitialLineLength) -> httpRequestDecoderSpec
.maxInitialLineLength((int) maxInitialLineLength.toBytes())); .maxInitialLineLength((int) maxInitialLineLength.toBytes()));
propertyMapper.from(nettyProperties.getH2cMaxContentLength()) propertyMapper.from(nettyProperties.getH2cMaxContentLength())
.whenNonNull()
.to((h2cMaxContentLength) -> httpRequestDecoderSpec .to((h2cMaxContentLength) -> httpRequestDecoderSpec
.h2cMaxContentLength((int) h2cMaxContentLength.toBytes())); .h2cMaxContentLength((int) h2cMaxContentLength.toBytes()));
propertyMapper.from(nettyProperties.getInitialBufferSize()) propertyMapper.from(nettyProperties.getInitialBufferSize())
.whenNonNull()
.to((initialBufferSize) -> httpRequestDecoderSpec.initialBufferSize((int) initialBufferSize.toBytes())); .to((initialBufferSize) -> httpRequestDecoderSpec.initialBufferSize((int) initialBufferSize.toBytes()));
propertyMapper.from(nettyProperties.isValidateHeaders()) propertyMapper.from(nettyProperties.isValidateHeaders()).to(httpRequestDecoderSpec::validateHeaders);
.whenNonNull()
.to(httpRequestDecoderSpec::validateHeaders);
return httpRequestDecoderSpec; return httpRequestDecoderSpec;
})); }));
} }