Search in sources :

Example 1 with NettyServerCustomizer

use of org.springframework.boot.web.embedded.netty.NettyServerCustomizer in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method verifyConnectionTimeout.

private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Integer expected) {
    if (expected == null) {
        then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class));
        return;
    }
    then(factory).should(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);
}
Also used : NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) ChannelOption(io.netty.channel.ChannelOption) HttpServer(reactor.netty.http.server.HttpServer)

Example 2 with NettyServerCustomizer

use of org.springframework.boot.web.embedded.netty.NettyServerCustomizer in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method verifyIdleTimeout.

private void verifyIdleTimeout(NettyReactiveWebServerFactory factory, Duration expected) {
    if (expected == null) {
        then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class));
        return;
    }
    then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
    NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
    HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
    Duration idleTimeout = httpServer.configuration().idleTimeout();
    assertThat(idleTimeout).isEqualTo(expected);
}
Also used : NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpServer(reactor.netty.http.server.HttpServer) Duration(java.time.Duration)

Example 3 with NettyServerCustomizer

use of org.springframework.boot.web.embedded.netty.NettyServerCustomizer in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method verifyMaxKeepAliveRequests.

private void verifyMaxKeepAliveRequests(NettyReactiveWebServerFactory factory, int expected) {
    then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
    NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
    HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
    int maxKeepAliveRequests = httpServer.configuration().maxKeepAliveRequests();
    assertThat(maxKeepAliveRequests).isEqualTo(expected);
}
Also used : NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpServer(reactor.netty.http.server.HttpServer)

Example 4 with NettyServerCustomizer

use of org.springframework.boot.web.embedded.netty.NettyServerCustomizer 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)

Example 5 with NettyServerCustomizer

use of org.springframework.boot.web.embedded.netty.NettyServerCustomizer in project spring-boot by spring-projects.

the class ReactiveWebServerFactoryAutoConfigurationTests method nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, Server.class, Undertow.class)).withUserConfiguration(DoubleRegistrationNettyServerCustomizerConfiguration.class, HttpHandlerConfiguration.class).withPropertyValues("server.port: 0").run((context) -> {
        NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
        NettyServerCustomizer customizer = context.getBean("serverCustomizer", NettyServerCustomizer.class);
        assertThat(factory.getServerCustomizers()).contains(customizer);
        then(customizer).should().apply(any(HttpServer.class));
    });
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpServer(reactor.netty.http.server.HttpServer) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

NettyServerCustomizer (org.springframework.boot.web.embedded.netty.NettyServerCustomizer)5 HttpServer (reactor.netty.http.server.HttpServer)5 Test (org.junit.jupiter.api.Test)2 NettyReactiveWebServerFactory (org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory)2 ChannelOption (io.netty.channel.ChannelOption)1 Duration (java.time.Duration)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)1 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)1 HttpRequestDecoderSpec (reactor.netty.http.server.HttpRequestDecoderSpec)1