Top Description Inners Fields Constructors Methods
reactor.netty5.http.server

public abstract Class HttpServer

extends ServerTransport<HttpServer, HttpServerConfig>
Class Inheritance
Known Direct Subclasses
reactor.netty5.http.server.HttpServerBind
Imports
java.net.SocketAddress, java.time.Duration, java.util.Objects, java.util.function.BiFunction, .BiPredicate, .Consumer, .Function, .Predicate, .Supplier, io.netty5.channel.group.ChannelGroup, io.netty5.handler.codec.DecoderException, io.netty5.handler.codec.http.HttpMessage, .HttpRequest, io.netty5.handler.ssl.JdkSslContext, .OpenSsl, .SslContext, io.netty5.handler.ssl.util.SelfSignedCertificate, org.reactivestreams.Publisher, reactor.core.publisher.Mono, reactor.netty5.Connection, .ConnectionObserver, reactor.netty5.channel.ChannelMetricsRecorder, reactor.netty5.http.Http2SettingsSpec, .HttpProtocol, reactor.netty5.http.logging.HttpMessageLogFactory, .ReactorNettyHttpMessageLogFactory, reactor.netty5.http.server.logging.AccessLog, .AccessLogArgProvider, .AccessLogFactory, reactor.netty5.internal.util.Metrics, reactor.netty5.tcp.SslProvider, reactor.netty5.transport.ServerTransport, reactor.util.Logger, .Loggers, reactor.util.context.Context

An HttpServer allows building in a safe immutable way an HTTP server that is materialized and connecting when bind() is ultimately called.

Examples:

HttpServer.create()
          .host("0.0.0.0")
          .handle((req, res) -> res.sendString(Flux.just("hello")))
          .bind()
          .block();

Authors
Stephane Maldini, Violeta Georgieva

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final HttpServer

Returns:

a new HttpServer
accessLog
(boolean
enable or disable the access log
enable
)

Enable or disable the access log.

public final HttpServer

Returns:

a new HttpServer
accessLog
(boolean
enable or disable the access log
enable
,
AccessLogFactory
the AccessLogFactory that creates an AccessLog given an AccessLogArgProvider
accessLogFactory
)

Enable or disable the access log and customize it through an AccessLogFactory.

public final HttpServer
bindAddress(Supplier<? extends SocketAddress>
A supplier of the address to bind to.
bindAddressSupplier
)

Overrides reactor.netty5.transport.Transport.bindAddress.

Set a new local address to which this transport should bind on subscribe.
public final HttpServer
channelGroup(ChannelGroup channelGroup)

Overrides reactor.netty5.transport.Transport.channelGroup.

Provide a ChannelGroup to hold all active connected channels.
public final HttpServer

Returns:

a new HttpServer
compress
(BiPredicate<HttpServerRequest, HttpServerResponse>
that returns true to compress the response.
predicate
)

Enable GZip response compression if the client request presents accept encoding headers and the provided java.util.function.Predicate matches.

public final HttpServer

Returns:

a new HttpServer
compress
(boolean
if true GZip response compression is enabled if the client request presents accept encoding, otherwise disabled.
compressionEnabled
)

Specifies whether GZip response compression is enabled if the client request presents accept encoding.

public final HttpServer

Returns:

a new HttpServer
compress
(int
compression is performed once response size exceeds the given value in bytes
minResponseSize
)

Enable GZip response compression if the client request presents accept encoding headers AND the response reaches a minimum threshold

public static HttpServer

Returns:

a new HttpServer
create
()

Prepare an HttpServer

public final HttpServer

Returns:

a new HttpServer
forwarded
(BiFunction<ConnectionInfo, HttpRequest, ConnectionInfo>
the forwarded header handler
handler
)

Specifies a custom request handler for deriving information about the connection.

public final HttpServer

Returns:

a new HttpServer
forwarded
(boolean
if true support for the "Forwarded" and "X-Forwarded-*" HTTP request headers for deriving information about the connection is enabled, otherwise disabled.
forwardedEnabled
)

Specifies whether support for the "Forwarded" and "X-Forwarded-*" HTTP request headers for deriving information about the connection is enabled.

public final HttpServer

Returns:

a new HttpServer
handle
(BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>>
an I/O handler that can dispose underlying connection when Publisher terminates. Only the first registered handler will subscribe to the returned Publisher while other will immediately cancel given a same Connection
handler
)

Attach an I/O handler to react on a connected client

public final HttpServer
host(String
the host to bind to.
host
)

Overrides reactor.netty5.transport.ServerTransport.host.

The host to which this server should bind.
public final HttpServer

Returns:

a new HttpServer
http2Settings
(Consumer<Http2SettingsSpec.Builder>
configures Http2SettingsSpec before requesting
http2Settings
)

Apply HTTP/2 configuration

public final HttpServer

Returns:

a new HttpServer
httpFormDecoder
(Consumer<HttpServerFormDecoderProvider.Builder>
HttpServerFormDecoderProvider.Builder for HTTP form decoder configuration
formDecoderBuilder
)

Apply HTTP form decoder configuration.

public final HttpServer

Returns:

a new HttpServer
httpMessageLogFactory
(HttpMessageLogFactory
the factory for generating the log message
httpMessageLogFactory
)

When HttpMessage is about to be logged the configured factory will be used for generating a sanitized log message.

public final HttpServer

Returns:

a new HttpServer
httpRequestDecoder
(Function<HttpRequestDecoderSpec, HttpRequestDecoderSpec>
a function to mutate the provided Http request decoder options
requestDecoderOptions
)

Configure the io.netty5.handler.codec.http.HttpServerCodec's request decoding options.

public final HttpServer

Returns:

a new HttpServer
idleTimeout
(Duration
an idle timeout on the connection when it is waiting for an HTTP request (resolution: ms)
idleTimeout
)

Specifies an idle timeout on the connection when it is waiting for an HTTP request (resolution: ms).

public final HttpServer

Returns:

a new HttpServer
mapHandle
(BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>>
A BiFunction to decorate the configured I/O handler
mapHandle
)

Decorate the configured I/O handler.

public final HttpServer

Returns:

a new HttpServer
maxKeepAliveRequests
(int
the maximum number of HTTP/1.1 requests which can be served until the connection is closed by the server
maxKeepAliveRequests
)

The maximum number of HTTP/1.1 requests which can be served until the connection is closed by the server.

public final HttpServer

Returns:

a new HttpServer
metrics
(boolean
true enables metrics collection; false disables it
enable
,
Function<String, String>
a function that receives the actual uri and returns the uri tag value that will be used for the metrics with reactor.netty5.Metrics#URI tag
uriTagValue
)

Whether to enable metrics to be collected and registered in Micrometer's globalRegistry under the name reactor.netty5.Metrics#HTTP_SERVER_PREFIX.

public final HttpServer
metrics(boolean
if true enables the metrics on the Transport.
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the ChannelMetricsRecorder
recorder
)

Overrides reactor.netty5.transport.Transport.metrics.

Specifies whether the metrics are enabled on the Transport.
public final HttpServer

Returns:

a new HttpServer
metrics
(boolean
true enables metrics collection; false disables it
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the metrics recorder that receives the collected metrics
recorder
,
Function<String, String>
a function that receives the actual uri and returns the uri value that will be used when the metrics are propagated to the recorder.
uriValue
)

Specifies whether the metrics are enabled on the HttpServer.

public final HttpServer

Returns:

a new HttpServer
noSSL
()

Removes any previously applied SSL configuration customization

public final HttpServer
port(int
The port to bind to.
port
)

Overrides reactor.netty5.transport.ServerTransport.port.

The port to which this server should bind.
public final HttpServer

Returns:

a new HttpServer
protocol
(HttpProtocol...
The various HttpProtocol this server will support
supportedProtocols
)

The HTTP protocol to support.

public final HttpServer

Returns:

a new HttpServer
proxyProtocol
(ProxyProtocolSupportType
proxyProtocolSupportType
)

Specifies whether support for the "HAProxy proxy protocol" for deriving information about the address of the remote peer is enabled.

public final HttpServer

Returns:

a new HttpServer starting the router on subscribe
route
(Consumer<? super HttpServerRoutes>
provides a route builder to be mutated in order to define routes.
routesBuilder
)

Define routes for the server through the provided HttpServerRoutes builder.

public final HttpServer

Returns:

a new HttpServer
secure
(Consumer<? super SslProvider.SslContextSpec>
builder callback for further customization of SslContext.
sslProviderBuilder
)

Apply an SSL configuration customization via the passed builder.

public final HttpServer

Returns:

a new HttpServer
secure
(Consumer<? super SslProvider.SslContextSpec>
builder callback for further customization of SslContext.
sslProviderBuilder
,
boolean
true enables redirecting HTTP to HTTPS by changing the scheme only but otherwise leaving the port the same. This configuration is applicable only for HTTP 1.x.
redirectHttpToHttps
)

Apply an SSL configuration customization via the passed builder.

public final HttpServer

Returns:

a new HttpServer
secure
(SslProvider
The provider to set when configuring SSL
sslProvider
)

Applies an SSL configuration via the passed SslProvider.

public final HttpServer

Returns:

a new HttpServer
secure
(SslProvider
The provider to set when configuring SSL
sslProvider
,
boolean
true enables redirecting HTTP to HTTPS by changing the scheme only but otherwise leaving the port the same. This configuration is applicable only for HTTP 1.x.
redirectHttpToHttps
)

Applies an SSL configuration via the passed SslProvider.

public Mono<Void>

Returns:

a Mono representing the completion of the warmup
warmup
()

Overrides reactor.netty5.transport.ServerTransport.warmup.

Based on the actual configuration, returns a Mono that triggers:
  • an initialization of the event loop groups
  • loads the necessary native libraries for the transport
  • loads the necessary native libraries for the security if there is such
public final HttpServer
wiretap(boolean
specifies whether the wire logger configuration will be added to the pipeline
enable
)

Overrides reactor.netty5.transport.Transport.wiretap.

Apply or remove a wire logger configuration using Transport category (logger), DEBUG logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.
Inherited from reactor.netty5.transport.ServerTransport:
bindbindNowbindNowbindUntilJavaShutdownchildAttrchildObservechildOptiondoOnBinddoOnBounddoOnConnectiondoOnUnbound