@Override protected void initServer() { this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .tcpConfiguration(server -> server.host(getHost())) .port(getPort()); }
@Override protected void initServer() { this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .tcpConfiguration(server -> server.host(getHost())) .port(getPort()); }
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.tcpConfiguration((tcpServer) -> tcpServer.runOn(resources) .addressSupplier(this::getListenAddress)); } else { server = server.tcpConfiguration( (tcpServer) -> tcpServer.addressSupplier(this::getListenAddress)); } if (getSsl() != null && getSsl().isEnabled()) { SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(getSsl(), getHttp2(), getSslStoreProvider()); server = sslServerCustomizer.apply(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); }
@Override protected TcpServer tcpConfiguration() { return source.tcpConfiguration(); }
@Override protected TcpServer tcpConfiguration() { return Objects.requireNonNull(tcpServerMapper.apply(source.tcpConfiguration()), "tcpServerMapper"); } }
@Override protected TcpServer tcpConfiguration() { return Objects.requireNonNull(tcpServerMapper.apply(source.tcpConfiguration()), "tcpServerMapper"); } }
/** * The port to which this server should bind. * * @param port The port to bind to. * * @return a new {@link HttpServer} */ public final HttpServer port(int port) { return tcpConfiguration(tcpServer -> tcpServer.port(port)); }
/** * The host to which this server should bind. * * @param host The host to bind to. * * @return a new {@link HttpServer} */ public final HttpServer host(String host) { return tcpConfiguration(tcpServer -> tcpServer.host(host)); }
@Override protected TcpServer tcpConfiguration() { return source.tcpConfiguration().secure(this.sslProvider); } }
@Override protected TcpServer tcpConfiguration() { return source.tcpConfiguration().bootstrap(this); }
/** * The host to which this server should bind. * * @param host The host to bind to. * * @return a new {@link HttpServer} */ public final HttpServer host(String host) { return tcpConfiguration(tcpServer -> tcpServer.host(host)); }
/** * Apply a wire logger configuration using {@link HttpServer} category * and {@code DEBUG} logger level * * @return a new {@link HttpServer} * @deprecated Use {@link HttpServer#wiretap(boolean)} */ @Deprecated public final HttpServer wiretap() { return tcpConfiguration(tcpServer -> tcpServer.bootstrap(b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER))); }
/** * Configure the {@link io.netty.handler.codec.http.HttpServerCodec}'s request decoding options. * * @param requestDecoderOptions a function to mutate the provided Http request decoder options * @return a new {@link HttpServer} */ public final HttpServer httpRequestDecoder(Function<HttpRequestDecoderSpec, HttpRequestDecoderSpec> requestDecoderOptions) { return tcpConfiguration( requestDecoderOptions.apply(new HttpRequestDecoderSpec()) .build()); }
/** * Apply a wire logger configuration using {@link HttpServer} category * and {@code DEBUG} logger level * * @return a new {@link HttpServer} * @deprecated Use {@link HttpServer#wiretap(boolean)} */ @Deprecated public final HttpServer wiretap() { return tcpConfiguration(tcpServer -> tcpServer.bootstrap(b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER))); }
/** * Configure the {@link io.netty.handler.codec.http.HttpServerCodec}'s request decoding options. * * @param requestDecoderOptions a function to mutate the provided Http request decoder options * @return a new {@link HttpServer} */ public final HttpServer httpRequestDecoder(Function<HttpRequestDecoderSpec, HttpRequestDecoderSpec> requestDecoderOptions) { return tcpConfiguration( requestDecoderOptions.apply(new HttpRequestDecoderSpec()) .build()); }
/** * The HTTP protocol to support. Default is {@link HttpProtocol#HTTP11}. * * @param supportedProtocols The various {@link HttpProtocol} this server will support * * @return a new {@link HttpServer} */ public final HttpServer protocol(HttpProtocol... supportedProtocols) { return tcpConfiguration(tcpServer -> tcpServer.bootstrap(b -> HttpServerConfiguration.protocols(b, supportedProtocols))); }
/** * The HTTP protocol to support. Default is {@link HttpProtocol#HTTP11}. * * @param supportedProtocols The various {@link HttpProtocol} this server will support * * @return a new {@link HttpServer} */ public final HttpServer protocol(HttpProtocol... supportedProtocols) { return tcpConfiguration(tcpServer -> tcpServer.bootstrap(b -> HttpServerConfiguration.protocols(b, supportedProtocols))); }
/** * Configure the * {@link ServerCookieEncoder} and {@link ServerCookieDecoder} * * @param encoder the preferred ServerCookieEncoder * @param decoder the preferred ServerCookieDecoder * * @return a new {@link HttpServer} */ public final HttpServer cookieCodec(ServerCookieEncoder encoder, ServerCookieDecoder decoder) { return tcpConfiguration(tcp -> tcp.bootstrap( b -> HttpServerConfiguration.cookieCodec(b, encoder, decoder))); }
@Test public void gettingOptionsDuplicates() { HttpServer server = HttpServer.create() .port(123) .host(("foo")) .compress(true); assertThat(server.tcpConfiguration().configure()) .isNotSameAs(HttpServer.DEFAULT_TCP_SERVER) .isNotSameAs(server.tcpConfiguration().configure()); }
@Test public void testRestart() { doTestRestart(HttpServer.create() .port(8080), HttpClient.create() .port(8080)); doTestRestart(HttpServer.create() // Any local address .tcpConfiguration(tcpServer -> tcpServer.addressSupplier(() -> new InetSocketAddress(8080))), HttpClient.create() .port(8080)); }