Search in sources :

Example 1 with HttpServer

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

the class NettyReactiveWebServerFactory method createHttpServer.

private HttpServer createHttpServer() {
    HttpServer server = HttpServer.create();
    if (this.resourceFactory != null) {
        LoopResources resources = this.resourceFactory.getLoopResources();
        Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?");
        server = server.runOn(resources).bindAddress(this::getListenAddress);
    } else {
        server = server.bindAddress(this::getListenAddress);
    }
    if (getSsl() != null && getSsl().isEnabled()) {
        server = customizeSslConfiguration(server);
    }
    if (getCompression() != null && getCompression().getEnabled()) {
        CompressionCustomizer compressionCustomizer = new CompressionCustomizer(getCompression());
        server = compressionCustomizer.apply(server);
    }
    server = server.protocol(listProtocols()).forwarded(this.useForwardHeaders);
    return applyCustomizers(server);
}
Also used : LoopResources(reactor.netty.resources.LoopResources) HttpServer(reactor.netty.http.server.HttpServer)

Example 2 with HttpServer

use of reactor.netty.http.server.HttpServer 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 3 with HttpServer

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

the class NettyReactiveWebServerFactory method getWebServer.

@Override
public WebServer getWebServer(HttpHandler httpHandler) {
    HttpServer httpServer = createHttpServer();
    ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter(httpHandler);
    NettyWebServer webServer = createNettyWebServer(httpServer, handlerAdapter, this.lifecycleTimeout, getShutdown());
    webServer.setRouteProviders(this.routeProviders);
    return webServer;
}
Also used : HttpServer(reactor.netty.http.server.HttpServer) ReactorHttpHandlerAdapter(org.springframework.http.server.reactive.ReactorHttpHandlerAdapter)

Example 4 with HttpServer

use of reactor.netty.http.server.HttpServer 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 5 with HttpServer

use of reactor.netty.http.server.HttpServer 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)

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