Polish "Add properties for Netty HttpDecoderSpec"

See gh-22367
This commit is contained in:
Andy Wilkinson
2020-07-17 20:19:19 +01:00
parent f068f9fc52
commit 0e8bf94289
4 changed files with 71 additions and 56 deletions

View File

@@ -43,6 +43,8 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.junit.jupiter.api.Test;
import reactor.netty.http.HttpDecoderSpec;
import reactor.netty.http.server.HttpRequestDecoderSpec;
import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog;
import org.springframework.boot.context.properties.bind.Bindable;
@@ -533,6 +535,35 @@ class ServerPropertiesTests {
.isEqualTo(UndertowOptions.DEFAULT_MAX_ENTITY_SIZE);
}
@Test
void nettyMaxChunkSizeMatchesHttpDecoderSpecDefault() {
assertThat(this.properties.getNetty().getMaxChunkSize().toBytes())
.isEqualTo(HttpDecoderSpec.DEFAULT_MAX_CHUNK_SIZE);
}
@Test
void nettyMaxInitialLineLenghtMatchesHttpDecoderSpecDefault() {
assertThat(this.properties.getNetty().getMaxInitialLineLength().toBytes())
.isEqualTo(HttpDecoderSpec.DEFAULT_MAX_INITIAL_LINE_LENGTH);
}
@Test
void nettyValidateHeadersMatchesHttpDecoderSpecDefault() {
assertThat(this.properties.getNetty().isValidateHeaders()).isEqualTo(HttpDecoderSpec.DEFAULT_VALIDATE_HEADERS);
}
@Test
void nettyH2cMaxContentLengthMatchesHttpDecoderSpecDefault() {
assertThat(this.properties.getNetty().getH2cMaxContentLength().toBytes())
.isEqualTo(HttpRequestDecoderSpec.DEFAULT_H2C_MAX_CONTENT_LENGTH);
}
@Test
void nettyInitialBufferSizeMatchesHttpDecoderSpecDefault() {
assertThat(this.properties.getNetty().getInitialBufferSize().toBytes())
.isEqualTo(HttpDecoderSpec.DEFAULT_INITIAL_BUFFER_SIZE);
}
private Connector getDefaultConnector() throws Exception {
return new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
}

View File

@@ -110,9 +110,9 @@ class NettyWebServerFactoryCustomizerTests {
}
@Test
void setHttpRequestDecoder() {
void configureHttpRequestDecoder() {
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
nettyProperties.setValidateHeaders(true);
nettyProperties.setValidateHeaders(false);
nettyProperties.setInitialBufferSize(DataSize.ofBytes(512));
nettyProperties.setH2cMaxContentLength(DataSize.ofKilobytes(1));
nettyProperties.setMaxChunkSize(DataSize.ofKilobytes(16));
@@ -123,28 +123,20 @@ class NettyWebServerFactoryCustomizerTests {
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
assertThat(decoder.validateHeaders()).isTrue();
assertThat(decoder.validateHeaders()).isFalse();
assertThat(decoder.initialBufferSize()).isEqualTo(nettyProperties.getInitialBufferSize().toBytes());
assertThat(decoder.h2cMaxContentLength()).isEqualTo(nettyProperties.getH2cMaxContentLength().toBytes());
assertThat(decoder.maxChunkSize()).isEqualTo(nettyProperties.getMaxChunkSize().toBytes());
assertThat(decoder.maxInitialLineLength()).isEqualTo(nettyProperties.getMaxInitialLineLength().toBytes());
}
@Test
void shouldNotSetAnyHttpRequestDecoderProperties() {
this.serverProperties.setMaxHttpHeaderSize(null);
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
this.customizer.customize(factory);
verify(factory, never()).addServerCustomizers(this.customizerCaptor.capture());
}
private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Integer expected) {
if (expected == null) {
verify(factory, never()).addServerCustomizers(any(NettyServerCustomizer.class));
return;
}
verify(factory, times(1)).addServerCustomizers(this.customizerCaptor.capture());
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
verify(factory, times(2)).addServerCustomizers(this.customizerCaptor.capture());
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
Map<ChannelOption<?>, ?> options = httpServer.configuration().options();
assertThat(options.get(ChannelOption.CONNECT_TIMEOUT_MILLIS)).isEqualTo(expected);