|
|
@ -26,6 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import org.mockito.Captor;
|
|
|
|
import org.mockito.Captor;
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
|
|
|
import reactor.netty.http.Http2SettingsSpec;
|
|
|
|
import reactor.netty.http.server.HttpRequestDecoderSpec;
|
|
|
|
import reactor.netty.http.server.HttpRequestDecoderSpec;
|
|
|
|
import reactor.netty.http.server.HttpServer;
|
|
|
|
import reactor.netty.http.server.HttpServer;
|
|
|
|
|
|
|
|
|
|
|
@ -126,9 +127,20 @@ class NettyWebServerFactoryCustomizerTests {
|
|
|
|
verifyMaxKeepAliveRequests(factory, 100);
|
|
|
|
verifyMaxKeepAliveRequests(factory, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void setHttp2MaxRequestHeaderSize() {
|
|
|
|
|
|
|
|
DataSize headerSize = DataSize.ofKilobytes(24);
|
|
|
|
|
|
|
|
this.serverProperties.getHttp2().setEnabled(true);
|
|
|
|
|
|
|
|
this.serverProperties.setMaxHttpRequestHeaderSize(headerSize);
|
|
|
|
|
|
|
|
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
|
|
|
|
|
|
|
this.customizer.customize(factory);
|
|
|
|
|
|
|
|
verifyHttp2MaxHeaderSize(factory, headerSize.toBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void configureHttpRequestDecoder() {
|
|
|
|
void configureHttpRequestDecoder() {
|
|
|
|
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
|
|
|
|
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
|
|
|
|
|
|
|
|
this.serverProperties.setMaxHttpRequestHeaderSize(DataSize.ofKilobytes(24));
|
|
|
|
nettyProperties.setValidateHeaders(false);
|
|
|
|
nettyProperties.setValidateHeaders(false);
|
|
|
|
nettyProperties.setInitialBufferSize(DataSize.ofBytes(512));
|
|
|
|
nettyProperties.setInitialBufferSize(DataSize.ofBytes(512));
|
|
|
|
nettyProperties.setH2cMaxContentLength(DataSize.ofKilobytes(1));
|
|
|
|
nettyProperties.setH2cMaxContentLength(DataSize.ofKilobytes(1));
|
|
|
@ -137,10 +149,11 @@ class NettyWebServerFactoryCustomizerTests {
|
|
|
|
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
|
|
|
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
|
|
|
this.customizer.customize(factory);
|
|
|
|
this.customizer.customize(factory);
|
|
|
|
then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
|
|
|
|
then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
|
|
|
|
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
|
|
|
|
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
|
|
|
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
|
|
|
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
|
|
|
HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
|
|
|
|
HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
|
|
|
|
assertThat(decoder.validateHeaders()).isFalse();
|
|
|
|
assertThat(decoder.validateHeaders()).isFalse();
|
|
|
|
|
|
|
|
assertThat(decoder.maxHeaderSize()).isEqualTo(this.serverProperties.getMaxHttpRequestHeaderSize().toBytes());
|
|
|
|
assertThat(decoder.initialBufferSize()).isEqualTo(nettyProperties.getInitialBufferSize().toBytes());
|
|
|
|
assertThat(decoder.initialBufferSize()).isEqualTo(nettyProperties.getInitialBufferSize().toBytes());
|
|
|
|
assertThat(decoder.h2cMaxContentLength()).isEqualTo(nettyProperties.getH2cMaxContentLength().toBytes());
|
|
|
|
assertThat(decoder.h2cMaxContentLength()).isEqualTo(nettyProperties.getH2cMaxContentLength().toBytes());
|
|
|
|
assertMaxChunkSize(nettyProperties, decoder);
|
|
|
|
assertMaxChunkSize(nettyProperties, decoder);
|
|
|
@ -189,4 +202,12 @@ class NettyWebServerFactoryCustomizerTests {
|
|
|
|
assertThat(maxKeepAliveRequests).isEqualTo(expected);
|
|
|
|
assertThat(maxKeepAliveRequests).isEqualTo(expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void verifyHttp2MaxHeaderSize(NettyReactiveWebServerFactory factory, long expected) {
|
|
|
|
|
|
|
|
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
|
|
|
|
|
|
|
|
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
|
|
|
|
|
|
|
|
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
|
|
|
|
|
|
|
|
Http2SettingsSpec decoder = httpServer.configuration().http2SettingsSpec();
|
|
|
|
|
|
|
|
assertThat(decoder.maxHeaderListSize()).isEqualTo(expected);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|