public abstract class HttpServer extends reactor.netty.transport.ServerTransport<HttpServer,HttpServerConfig>
ServerTransport.bind() is ultimately called.
Examples:
HttpServer.create()
.host("0.0.0.0")
.handle((req, res) -> res.sendString(Flux.just("hello")))
.bind()
.block();
| Constructor and Description |
|---|
HttpServer() |
| Modifier and Type | Method and Description |
|---|---|
HttpServer |
bindAddress(java.util.function.Supplier<? extends SocketAddress> bindAddressSupplier) |
HttpServer |
channelGroup(ChannelGroup channelGroup) |
HttpServer |
compress(java.util.function.BiPredicate<HttpServerRequest,HttpServerResponse> predicate)
Enable GZip response compression if the client request presents accept encoding
headers and the provided
Predicate matches. |
HttpServer |
compress(boolean compressionEnabled)
Specifies whether GZip response compression is enabled if the client request
presents accept encoding.
|
HttpServer |
compress(int minResponseSize)
Enable GZip response compression if the client request presents accept encoding
headers AND the response reaches a minimum threshold
|
HttpServer |
cookieCodec(ServerCookieEncoder encoder)
Configure the
ServerCookieEncoder; ServerCookieDecoder will be
chosen based on the encoder |
HttpServer |
cookieCodec(ServerCookieEncoder encoder,
ServerCookieDecoder decoder)
Configure the
ServerCookieEncoder and ServerCookieDecoder |
static HttpServer |
create()
Prepare an
HttpServer |
HttpServer |
forwarded(java.util.function.BiFunction<ConnectionInfo,HttpRequest,ConnectionInfo> handler)
Specifies a custom request handler for deriving information about the connection.
|
HttpServer |
forwarded(boolean forwardedEnabled)
Specifies whether support for the
"Forwarded" and "X-Forwarded-*"
HTTP request headers for deriving information about the connection is enabled. |
static HttpServer |
from(TcpServer tcpServer)
Deprecated.
Use
HttpServer methods for TCP level configurations. This method
will be removed in version 1.1.0. |
HttpServer |
handle(java.util.function.BiFunction<? super HttpServerRequest,? super HttpServerResponse,? extends Publisher<Void>> handler)
Attach an I/O handler to react on a connected client
|
HttpServer |
host(String host) |
HttpServer |
http2Settings(java.util.function.Consumer<Http2SettingsSpec.Builder> http2Settings)
Apply HTTP/2 configuration
|
HttpServer |
httpRequestDecoder(java.util.function.Function<HttpRequestDecoderSpec,HttpRequestDecoderSpec> requestDecoderOptions)
Configure the
HttpServerCodec's request decoding options. |
HttpServer |
mapHandle(java.util.function.BiFunction<? super Mono<Void>,? super Connection,? extends Mono<Void>> mapHandle)
Decorate the configured I/O handler.
|
HttpServer |
metrics(boolean enable,
java.util.function.Function<String,String> uriTagValue)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry
under the name Metrics.HTTP_SERVER_PREFIX. |
HttpServer |
metrics(boolean enable,
java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder) |
HttpServer |
metrics(boolean enable,
java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder,
java.util.function.Function<String,String> uriValue)
Specifies whether the metrics are enabled on the
HttpServer. |
HttpServer |
noSSL()
Removes any previously applied SSL configuration customization
|
HttpServer |
port(int port) |
HttpServer |
protocol(HttpProtocol... supportedProtocols)
The HTTP protocol to support.
|
HttpServer |
proxyProtocol(ProxyProtocolSupportType proxyProtocolSupportType)
Specifies whether support for the
"HAProxy proxy protocol"
for deriving information about the address of the remote peer is enabled. |
HttpServer |
route(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
Define routes for the server through the provided
HttpServerRoutes builder. |
HttpServer |
secure(java.util.function.Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
Apply an SSL configuration customization via the passed builder.
|
HttpServer |
secure(SslProvider sslProvider)
Applies an SSL configuration via the passed
SslProvider. |
HttpServer |
tcpConfiguration(java.util.function.Function<? super TcpServer,? extends TcpServer> tcpMapper)
Deprecated.
Use
HttpServer methods for TCP level configurations. This method
will be removed in version 1.1.0. |
HttpServer |
wiretap(boolean enable) |
bind, bindNow, bindNow, bindUntilJavaShutdown, childAttr, childObserve, childOption, doOnBind, doOnBound, doOnConnection, doOnUnboundattr, configuration, doOnChannelInit, duplicate, metrics, observe, option, runOn, runOn, runOn, wiretap, wiretap, wiretap, wiretappublic static HttpServer create()
HttpServerHttpServer@Deprecated public static HttpServer from(TcpServer tcpServer)
HttpServer methods for TCP level configurations. This method
will be removed in version 1.1.0.HttpServerHttpServerpublic final HttpServer bindAddress(java.util.function.Supplier<? extends SocketAddress> bindAddressSupplier)
bindAddress in class reactor.netty.transport.Transport<HttpServer,HttpServerConfig>public final HttpServer channelGroup(ChannelGroup channelGroup)
channelGroup in class reactor.netty.transport.Transport<HttpServer,HttpServerConfig>public final HttpServer compress(java.util.function.BiPredicate<HttpServerRequest,HttpServerResponse> predicate)
Predicate matches.
Note: the passed HttpServerRequest and HttpServerResponse
should be considered read-only and the implement SHOULD NOT consume or
write the request/response in this predicate.
predicate - that returns true to compress the response.HttpServerpublic final HttpServer compress(boolean compressionEnabled)
compressionEnabled - if true GZip response compression
is enabled if the client request presents accept encoding, otherwise disabled.HttpServerpublic final HttpServer compress(int minResponseSize)
minResponseSize - compression is performed once response size exceeds the given
value in bytesHttpServerpublic final HttpServer cookieCodec(ServerCookieEncoder encoder)
ServerCookieEncoder; ServerCookieDecoder will be
chosen based on the encoderencoder - the preferred ServerCookieEncoderHttpServerpublic final HttpServer cookieCodec(ServerCookieEncoder encoder, ServerCookieDecoder decoder)
ServerCookieEncoder and ServerCookieDecoderencoder - the preferred ServerCookieEncoderdecoder - the preferred ServerCookieDecoderHttpServerpublic final HttpServer forwarded(boolean forwardedEnabled)
"Forwarded" and "X-Forwarded-*"
HTTP request headers for deriving information about the connection is enabled.forwardedEnabled - if true support for the "Forwarded" and "X-Forwarded-*"
HTTP request headers for deriving information about the connection is enabled,
otherwise disabled.HttpServerpublic final HttpServer forwarded(java.util.function.BiFunction<ConnectionInfo,HttpRequest,ConnectionInfo> handler)
handler - the forwarded header handlerHttpServerpublic final HttpServer handle(java.util.function.BiFunction<? super HttpServerRequest,? super HttpServerResponse,? extends Publisher<Void>> handler)
handler - 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
ConnectionHttpServerpublic final HttpServer host(String host)
host in class reactor.netty.transport.ServerTransport<HttpServer,HttpServerConfig>public final HttpServer http2Settings(java.util.function.Consumer<Http2SettingsSpec.Builder> http2Settings)
http2Settings - configures Http2SettingsSpec before requestingHttpServerpublic final HttpServer httpRequestDecoder(java.util.function.Function<HttpRequestDecoderSpec,HttpRequestDecoderSpec> requestDecoderOptions)
HttpServerCodec's request decoding options.requestDecoderOptions - a function to mutate the provided Http request decoder optionsHttpServerpublic final HttpServer mapHandle(java.util.function.BiFunction<? super Mono<Void>,? super Connection,? extends Mono<Void>> mapHandle)
handle(BiFunction).mapHandle - A BiFunction to decorate the configured I/O handlerHttpServerpublic final HttpServer metrics(boolean enable, java.util.function.Function<String,String> uriTagValue)
globalRegistry
under the name Metrics.HTTP_SERVER_PREFIX.
uriTagValue function receives the actual uri and returns the uri tag value
that will be used for the metrics with Metrics.URI tag.
For example instead of using the actual uri "/users/1" as uri tag value, templated uri
"/users/{id}" can be used.
Note: It is strongly recommended applications to configure an upper limit for the number of the URI tags. For example:
Metrics.globalRegistry
.config()
.meterFilter(MeterFilter.maximumAllowableTags(HTTP_SERVER_PREFIX, URI, 100, MeterFilter.deny()));
By default metrics are not enabled.
enable - true enables metrics collection; false disables ituriTagValue - a function that receives the actual uri and returns the uri tag value
that will be used for the metrics with Metrics.URI tagHttpServerpublic final HttpServer metrics(boolean enable, java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder)
metrics in class reactor.netty.transport.Transport<HttpServer,HttpServerConfig>public final HttpServer metrics(boolean enable, java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder, java.util.function.Function<String,String> uriValue)
HttpServer.
All generated metrics are provided to the specified recorder which is only
instantiated if metrics are being enabled.
uriValue function receives the actual uri and returns the uri value
that will be used when the metrics are propagated to the recorder.
For example instead of using the actual uri "/users/1" as uri value, templated uri
"/users/{id}" can be used.
enable - true enables metrics collection; false disables itrecorder - a supplier for the metrics recorder that receives the collected metricsuriValue - a function that receives the actual uri and returns the uri value
that will be used when the metrics are propagated to the recorder.HttpServerpublic final HttpServer noSSL()
HttpServerpublic final HttpServer port(int port)
port in class reactor.netty.transport.ServerTransport<HttpServer,HttpServerConfig>public final HttpServer protocol(HttpProtocol... supportedProtocols)
HttpProtocol.HTTP11.supportedProtocols - The various HttpProtocol this server will supportHttpServerpublic final HttpServer proxyProtocol(ProxyProtocolSupportType proxyProtocolSupportType)
"HAProxy proxy protocol"
for deriving information about the address of the remote peer is enabled.proxyProtocolSupportType - ProxyProtocolSupportType.ON
to enable support for the "HAProxy proxy protocol"
for deriving information about the address of the remote peer.
ProxyProtocolSupportType.OFF to disable the proxy protocol support.ProxyProtocolSupportType.AUTO
then each connection of the same HttpServer will auto detect whether there is proxy protocol,
so HttpServer can accept requests with or without proxy protocol at the same time.
HttpServerpublic final HttpServer route(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
HttpServerRoutes builder.routesBuilder - provides a route builder to be mutated in order to define routes.HttpServer starting the router on subscribepublic final HttpServer secure(java.util.function.Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
SslContext to be passed to with a default value of
10 seconds handshake timeout unless the environment property reactor.netty.tcp.sslHandshakeTimeout is set.
If SelfSignedCertificate needs to be used, the sample below can be
used. Note that SelfSignedCertificate should not be used in production.
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContextBuilder sslContextBuilder =
SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
secure(sslContextSpec -> sslContextSpec.sslContext(sslContextBuilder));
sslProviderBuilder - builder callback for further customization of SslContext.HttpServerpublic final HttpServer secure(SslProvider sslProvider)
SslProvider.
If SelfSignedCertificate needs to be used, the sample below can be
used. Note that SelfSignedCertificate should not be used in production.
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContextBuilder sslContextBuilder =
SslContextBuilder.forServer(cert.certificate(), cert.privateKey());
secure(sslContextSpec -> sslContextSpec.sslContext(sslContextBuilder));
sslProvider - The provider to set when configuring SSLHttpServer@Deprecated public final HttpServer tcpConfiguration(java.util.function.Function<? super TcpServer,? extends TcpServer> tcpMapper)
HttpServer methods for TCP level configurations. This method
will be removed in version 1.1.0.TcpServer mapping function to update TCP configuration and
return an enriched HttpServer to use.tcpMapper - A TcpServer mapping function to update TCP configuration and
return an enriched HttpServer to use.HttpServerpublic final HttpServer wiretap(boolean enable)
wiretap in class reactor.netty.transport.Transport<HttpServer,HttpServerConfig>