Search in sources :

Example 6 with HttpServer

use of reactor.netty.http.server.HttpServer in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method configureHttpRequestDecoder.

@Test
void configureHttpRequestDecoder() {
    ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
    nettyProperties.setValidateHeaders(false);
    nettyProperties.setInitialBufferSize(DataSize.ofBytes(512));
    nettyProperties.setH2cMaxContentLength(DataSize.ofKilobytes(1));
    nettyProperties.setMaxChunkSize(DataSize.ofKilobytes(16));
    nettyProperties.setMaxInitialLineLength(DataSize.ofKilobytes(32));
    NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
    this.customizer.customize(factory);
    then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
    NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
    HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
    HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
    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());
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpRequestDecoderSpec(reactor.netty.http.server.HttpRequestDecoderSpec) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) HttpServer(reactor.netty.http.server.HttpServer) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServer (reactor.netty.http.server.HttpServer)6 NettyServerCustomizer (org.springframework.boot.web.embedded.netty.NettyServerCustomizer)4 ChannelOption (io.netty.channel.ChannelOption)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1 NettyReactiveWebServerFactory (org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory)1 ReactorHttpHandlerAdapter (org.springframework.http.server.reactive.ReactorHttpHandlerAdapter)1 HttpRequestDecoderSpec (reactor.netty.http.server.HttpRequestDecoderSpec)1 LoopResources (reactor.netty.resources.LoopResources)1