Class NettyHttpServerConfiguration
- All Implemented Interfaces:
ServerContextPathProvider
NettyHttpServer
.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Access logger configuration.static class
Abstract class for configuring the Netty event loop.static class
Allows configuration of properties for theAbstractFileBodyWriter
.static class
Http2 settings.static final class
Configuration for the experimental HTTP/3 server.static enum
Sets the manner in which the HTTP server is configured to receive requests.static final class
Netty listener configuration.static class
Configuration for Netty parent.static class
Configuration for Netty worker.Nested classes/interfaces inherited from class io.micronaut.http.server.HttpServerConfiguration
HttpServerConfiguration.CorsConfiguration, HttpServerConfiguration.HostResolutionConfiguration, HttpServerConfiguration.HttpLocaleResolutionConfigurationProperties, HttpServerConfiguration.MultipartConfiguration
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
The default chunk supported value.static final int
The default compression level.static final int
The default compression threshold.static final boolean
The default value for eager parsing.static final int
Default value forNettyHttpServerConfiguration.Http3Settings.getInitialMaxData()
.static final int
static final int
static final int
static final int
The default initial buffer size value.static final int
The default value for eager parsing.static final boolean
The default configuration for boolean flag indicating whether to add connection header `keep-alive` to responses with HttpStatus > 499.static final int
The default max chunk size.static final int
The default max header size.static final int
The default max initial line length.static final boolean
The default use netty's native transport flag.static final boolean
The default validate headers value.Fields inherited from class io.micronaut.http.server.HttpServerConfiguration
DEFAULT_DATEHEADER, DEFAULT_DISPATCH_OPTIONS_REQUESTS, DEFAULT_DUAL_PROTOCOL, DEFAULT_HTTP_TO_HTTPS_REDIRECT, DEFAULT_IDLE_TIME_MINUTES, DEFAULT_LOG_HANDLED_EXCEPTIONS, DEFAULT_MAX_REQUEST_SIZE, DEFAULT_PORT, DEFAULT_RANDOM_PORT, DEFAULT_READ_IDLE_TIME_MINUTES, DEFAULT_WRITE_IDLE_TIME_MINUTES, PREFIX
-
Constructor Summary
ConstructorDescriptionDefault empty constructor.NettyHttpServerConfiguration
(ApplicationConfiguration applicationConfiguration) NettyHttpServerConfiguration
(ApplicationConfiguration applicationConfiguration, List<ChannelPipelineListener> pipelineCustomizers) -
Method Summary
Modifier and TypeMethodDescriptionReturns the AccessLogger configuration.int
The default compression level.int
The default compression threshold.getHttp2()
Returns the Http2Settings.getHttp3()
Returns the Http3Settings.int
The initial buffer size.int
Maximum number of buffers to keep around in JSON parsing before they should be consolidated.Get the explicit netty listener configurations, ornull
if they should be implicit.Optional<io.netty.handler.logging.LogLevel>
The serverLogLevel
to enable.int
The maximum chunk size.int
The maximum size of the body of the HTTP1.1 request used to upgrade a connection to HTTP2 clear-text (h2c).int
The maximum size of an individual HTTP setter.int
The maximum length of the initial HTTP request line.The path pattern to use for logging incoming connections to pcap.boolean
Whether chunked requests are supported.boolean
If a 100-continue response is detected but the content length is too large then true means close the connection.boolean
Parse incoming JSON data eagerly, before route binding.boolean
boolean
Prior to 4.4.0, the Micronaut HTTP server used a multi-pipeline approach for handling HTTP/2 connections where every request got its own netty pipeline with HTTP/2 to HTTP/1.1 converters on the pipeline.boolean
Whether to use netty's native transport (epoll or kqueue) if available.boolean
Whether to validate headers.void
setAccessLogger
(NettyHttpServerConfiguration.AccessLogger accessLogger) Sets the AccessLogger configuration.void
setChildOptions
(Map<io.netty.channel.ChannelOption, Object> childOptions) Sets the Netty child worker options.void
setChunkedSupported
(boolean chunkedSupported) Sets whether chunked transfer encoding is supported.void
setCloseOnExpectationFailed
(boolean closeOnExpectationFailed) If a 100-continue response is detected but the content length is too large then true means close the connection.void
setCompressionLevel
(int compressionLevel) Sets the compression level (0-9).void
setCompressionThreshold
(int compressionThreshold) Sets the minimum size of a request body must be in order to be compressed.void
setEagerParsing
(boolean eagerParsing) Parse incoming JSON data eagerly, before route binding.void
setFallbackProtocol
(String fallbackProtocol) Sets the fallback protocol to use when negotiating via ALPN.void
setFileTypeHandlerConfiguration
(@NonNull NettyHttpServerConfiguration.FileTypeHandlerConfiguration fileTypeHandlerConfiguration) Sets the file type handler configuration.void
Sets the Http2Settings.void
setHttp3Settings
(NettyHttpServerConfiguration.Http3Settings http3Settings) Sets the Http3Settings.void
setInitialBufferSize
(int initialBufferSize) Sets the initial buffer size.void
setJsonBufferMaxComponents
(int jsonBufferMaxComponents) Maximum number of buffers to keep around in JSON parsing before they should be consolidated.void
setKeepAliveOnServerError
(boolean keepAliveOnServerError) Whether to send connection keep alive on internal server errors.void
setLegacyMultiplexHandlers
(boolean legacyMultiplexHandlers) Prior to 4.4.0, the Micronaut HTTP server used a multi-pipeline approach for handling HTTP/2 connections where every request got its own netty pipeline with HTTP/2 to HTTP/1.1 converters on the pipeline.void
Set the explicit netty listener configurations, ornull
if they should be implicit.void
setLogLevel
(io.netty.handler.logging.LogLevel logLevel) Sets the Netty log level.void
setMaxChunkSize
(int maxChunkSize) Sets the maximum size of any single request chunk.void
setMaxH2cUpgradeRequestSize
(int maxH2cUpgradeRequestSize) Sets the maximum size of the body of the HTTP1.1 request used to upgrade a connection to HTTP2 clear-text (h2c).void
setMaxHeaderSize
(int maxHeaderSize) Sets the maximum size of any one header.void
setMaxInitialLineLength
(int maxInitialLineLength) Sets the maximum initial line length for the HTTP request.void
setOptions
(Map<io.netty.channel.ChannelOption, Object> options) Sets the channel options.void
Sets the parent event loop configuration.void
setPcapLoggingPathPattern
(String pcapLoggingPathPattern) The path pattern to use for logging incoming connections to pcap.void
Set the server type.void
setUseNativeTransport
(boolean useNativeTransport) Sets whether to use netty's native transport (epoll or kqueue) if available .void
setValidateHeaders
(boolean validateHeaders) Sets whether to validate incoming headers.void
Sets the worker event loop configuration.Methods inherited from class io.micronaut.http.server.HttpServerConfiguration
getApplicationConfiguration, getClientAddressHeader, getContextPath, getCors, getDefaultCharset, getHost, getHostResolution, getHttpVersion, getIdleTimeout, getLocaleResolution, getMaxRequestSize, getMultipart, getPort, getReadIdleTimeout, getReadTimeout, getServerHeader, getThreadSelection, getWriteIdleTimeout, isDateHeader, isDispatchOptionsRequests, isDualProtocol, isHttpToHttpsRedirect, isLogHandledExceptions, isValidateUrl, setClientAddressHeader, setContextPath, setCors, setDateHeader, setDefaultCharset, setDispatchOptionsRequests, setDualProtocol, setHost, setHostResolution, setHttpToHttpsRedirect, setHttpVersion, setIdleTimeout, setLocaleResolution, setLogHandledExceptions, setMaxRequestSize, setMultipart, setPort, setReadIdleTimeout, setReadTimeout, setServerHeader, setThreadSelection, setValidateUrl, setWriteIdleTimeout
-
Field Details
-
DEFAULT_USE_NATIVE_TRANSPORT
public static final boolean DEFAULT_USE_NATIVE_TRANSPORTThe default use netty's native transport flag.- See Also:
-
DEFAULT_MAXINITIALLINELENGTH
public static final int DEFAULT_MAXINITIALLINELENGTHThe default max initial line length.- See Also:
-
DEFAULT_MAXHEADERSIZE
public static final int DEFAULT_MAXHEADERSIZEThe default max header size.- See Also:
-
DEFAULT_MAXCHUNKSIZE
public static final int DEFAULT_MAXCHUNKSIZEThe default max chunk size.- See Also:
-
DEFAULT_CHUNKSUPPORTED
public static final boolean DEFAULT_CHUNKSUPPORTEDThe default chunk supported value.- See Also:
-
DEFAULT_VALIDATEHEADERS
public static final boolean DEFAULT_VALIDATEHEADERSThe default validate headers value.- See Also:
-
DEFAULT_INITIALBUFFERSIZE
public static final int DEFAULT_INITIALBUFFERSIZEThe default initial buffer size value.- See Also:
-
DEFAULT_COMPRESSIONTHRESHOLD
public static final int DEFAULT_COMPRESSIONTHRESHOLDThe default compression threshold.- See Also:
-
DEFAULT_COMPRESSIONLEVEL
public static final int DEFAULT_COMPRESSIONLEVELThe default compression level.- See Also:
-
DEFAULT_KEEP_ALIVE_ON_SERVER_ERROR
public static final boolean DEFAULT_KEEP_ALIVE_ON_SERVER_ERRORThe default configuration for boolean flag indicating whether to add connection header `keep-alive` to responses with HttpStatus > 499.- See Also:
-
DEFAULT_EAGER_PARSING
public static final boolean DEFAULT_EAGER_PARSINGThe default value for eager parsing.- Since:
- 4.0.0
- See Also:
-
DEFAULT_JSON_BUFFER_MAX_COMPONENTS
public static final int DEFAULT_JSON_BUFFER_MAX_COMPONENTSThe default value for eager parsing.- Since:
- 4.0.0
- See Also:
-
DEFAULT_HTTP3_INITIAL_MAX_DATA
public static final int DEFAULT_HTTP3_INITIAL_MAX_DATADefault value forNettyHttpServerConfiguration.Http3Settings.getInitialMaxData()
.- Since:
- 4.0.0
- See Also:
-
DEFAULT_HTTP3_INITIAL_MAX_STREAM_DATA_BIDIRECTIONAL_LOCAL
public static final int DEFAULT_HTTP3_INITIAL_MAX_STREAM_DATA_BIDIRECTIONAL_LOCALDefault value forNettyHttpServerConfiguration.Http3Settings.getInitialMaxStreamDataBidirectionalLocal()
.- Since:
- 4.0.0
- See Also:
-
DEFAULT_HTTP3_INITIAL_MAX_STREAM_DATA_BIDIRECTIONAL_REMOTE
public static final int DEFAULT_HTTP3_INITIAL_MAX_STREAM_DATA_BIDIRECTIONAL_REMOTEDefault value forNettyHttpServerConfiguration.Http3Settings.getInitialMaxStreamDataBidirectionalRemote()
.- Since:
- 4.0.0
- See Also:
-
DEFAULT_HTTP3_INITIAL_MAX_STREAMS_BIDIRECTIONAL
public static final int DEFAULT_HTTP3_INITIAL_MAX_STREAMS_BIDIRECTIONAL- Since:
- 4.0.0
- See Also:
-
-
Constructor Details
-
NettyHttpServerConfiguration
public NettyHttpServerConfiguration()Default empty constructor. -
NettyHttpServerConfiguration
- Parameters:
applicationConfiguration
- The application configuration
-
NettyHttpServerConfiguration
@Inject public NettyHttpServerConfiguration(ApplicationConfiguration applicationConfiguration, List<ChannelPipelineListener> pipelineCustomizers) - Parameters:
applicationConfiguration
- The application configurationpipelineCustomizers
- A list of pipeline customizers
-
-
Method Details
-
getServerType
- Returns:
- Sets the server type.
- See Also:
-
isCloseOnExpectationFailed
public boolean isCloseOnExpectationFailed()If a 100-continue response is detected but the content length is too large then true means close the connection. otherwise the connection will remain open and data will be consumed and discarded until the next request is received.only relevant when
NettyHttpServerConfiguration.HttpServerType.FULL_CONTENT
is set- Returns:
- True if the connection should be closed
- See Also:
-
setServerType(HttpServerType)
HttpObjectAggregator
-
setCloseOnExpectationFailed
public void setCloseOnExpectationFailed(boolean closeOnExpectationFailed) If a 100-continue response is detected but the content length is too large then true means close the connection. otherwise the connection will remain open and data will be consumed and discarded until the next request is received.only relevant when
NettyHttpServerConfiguration.HttpServerType.FULL_CONTENT
is set- Parameters:
closeOnExpectationFailed
- True if the connection should be closed- See Also:
-
setServerType(HttpServerType)
HttpObjectAggregator
-
setServerType
public void setServerType(@Nullable @Nullable NettyHttpServerConfiguration.HttpServerType serverType) Set the server type.- Parameters:
serverType
- The server type
-
getAccessLogger
Returns the AccessLogger configuration.- Returns:
- The AccessLogger configuration.
-
setAccessLogger
Sets the AccessLogger configuration.- Parameters:
accessLogger
- The configuration .
-
getHttp2
Returns the Http2Settings.- Returns:
- The Http2Settings.
-
setHttp2
Sets the Http2Settings.- Parameters:
http2
- The Http2Settings.
-
getHttp3
Returns the Http3Settings.- Returns:
- The Http3Settings.
-
setHttp3Settings
Sets the Http3Settings.- Parameters:
http3Settings
- The Http3Settings.
-
getPipelineCustomizers
- Returns:
- The pipeline customizers
-
getFallbackProtocol
- Returns:
- The fallback protocol to use when negotiating via ALPN
- See Also:
-
ApplicationProtocolNames
-
setFallbackProtocol
Sets the fallback protocol to use when negotiating via ALPN.- Parameters:
fallbackProtocol
- The fallback protocol to use when negotiating via ALPN- See Also:
-
ApplicationProtocolNames
-
getLogLevel
The serverLogLevel
to enable.- Returns:
- The server
LogLevel
to enable
-
getMaxInitialLineLength
public int getMaxInitialLineLength()The maximum length of the initial HTTP request line. Defaults to 4096.- Returns:
- The maximum length of the initial HTTP request line
-
getMaxHeaderSize
public int getMaxHeaderSize()The maximum size of an individual HTTP setter. Defaults to 8192.- Returns:
- The maximum size of an individual HTTP setter
-
getMaxChunkSize
public int getMaxChunkSize()The maximum chunk size. Defaults to 8192.- Returns:
- The maximum chunk size
-
getMaxH2cUpgradeRequestSize
public int getMaxH2cUpgradeRequestSize()The maximum size of the body of the HTTP1.1 request used to upgrade a connection to HTTP2 clear-text (h2c). This initial request cannot be streamed and is instead buffered in full, so the default value (8192) is relatively small. If this value is too small for your use case, instead consider using an empty initial "upgrade request" (e.g.OPTIONS /
), or switch to normal HTTP2.Does not affect normal HTTP2 (TLS).
- Returns:
- The maximum content length of the request.
-
isChunkedSupported
public boolean isChunkedSupported()Whether chunked requests are supported.- Returns:
- Whether chunked requests are supported.
-
isUseNativeTransport
public boolean isUseNativeTransport()Whether to use netty's native transport (epoll or kqueue) if available.- Returns:
- To use netty's native transport (epoll or kqueue) if available.
-
isValidateHeaders
public boolean isValidateHeaders()Whether to validate headers.- Returns:
- Whether to validate headers
-
getInitialBufferSize
public int getInitialBufferSize()The initial buffer size. Defaults to 128.- Returns:
- The initial buffer size.
-
getCompressionThreshold
public int getCompressionThreshold()The default compression threshold. Defaults to 1024.A value
< 0
indicates compression should never be enabled.- Returns:
- The compression threshold.
-
getCompressionLevel
public int getCompressionLevel()The default compression level. Default value (6).- Returns:
- The compression level.
-
getChildOptions
- Returns:
- The Netty child channel options.
- See Also:
-
ServerBootstrap.childOption(io.netty.channel.ChannelOption, Object)
-
getOptions
- Returns:
- The Netty channel options.
- See Also:
-
ServerBootstrap.childOption(io.netty.channel.ChannelOption, Object)
-
getWorker
- Returns:
- Configuration for the worker
EventLoopGroup
-
getFileTypeHandlerConfiguration
@NonNull public @NonNull NettyHttpServerConfiguration.FileTypeHandlerConfiguration getFileTypeHandlerConfiguration()- Returns:
- The file type handler configuration.
- Since:
- 3.1.0
-
setFileTypeHandlerConfiguration
@Inject public void setFileTypeHandlerConfiguration(@NonNull @NonNull NettyHttpServerConfiguration.FileTypeHandlerConfiguration fileTypeHandlerConfiguration) Sets the file type handler configuration.- Parameters:
fileTypeHandlerConfiguration
- The file type handler configuration- Since:
- 3.1.0
-
getParent
- Returns:
- Configuration for the parent
EventLoopGroup
-
isKeepAliveOnServerError
public boolean isKeepAliveOnServerError()- Returns:
- True if the connection should be kept alive on internal server errors
-
setChildOptions
Sets the Netty child worker options.- Parameters:
childOptions
- The options
-
setOptions
Sets the channel options.- Parameters:
options
- The channel options
-
setWorker
Sets the worker event loop configuration.- Parameters:
worker
- The worker config
-
setParent
Sets the parent event loop configuration.- Parameters:
parent
- The parent config
-
setMaxInitialLineLength
Sets the maximum initial line length for the HTTP request. Default value (4096).- Parameters:
maxInitialLineLength
- The max length
-
setMaxHeaderSize
Sets the maximum size of any one header. Default value (8192).- Parameters:
maxHeaderSize
- The max header size
-
setMaxChunkSize
Sets the maximum size of any single request chunk. Default value (8192).- Parameters:
maxChunkSize
- The max chunk size
-
setMaxH2cUpgradeRequestSize
public void setMaxH2cUpgradeRequestSize(int maxH2cUpgradeRequestSize) Sets the maximum size of the body of the HTTP1.1 request used to upgrade a connection to HTTP2 clear-text (h2c). This initial request cannot be streamed and is instead buffered in full, so the default value (8192) is relatively small. If this value is too small for your use case, instead consider using an empty initial "upgrade request" (e.g.OPTIONS /
), or switch to normal HTTP2.Does not affect normal HTTP2 (TLS).
- Parameters:
maxH2cUpgradeRequestSize
- The maximum content length of the request.
-
setChunkedSupported
public void setChunkedSupported(boolean chunkedSupported) Sets whether chunked transfer encoding is supported. Default value (true).- Parameters:
chunkedSupported
- True if it is supported
-
setUseNativeTransport
public void setUseNativeTransport(boolean useNativeTransport) Sets whether to use netty's native transport (epoll or kqueue) if available . Default value (false).- Parameters:
useNativeTransport
- True if netty's native transport should be use if available.
-
setValidateHeaders
public void setValidateHeaders(boolean validateHeaders) Sets whether to validate incoming headers. Default value (true).- Parameters:
validateHeaders
- True if headers should be validated.
-
setInitialBufferSize
public void setInitialBufferSize(int initialBufferSize) Sets the initial buffer size. Default value (128).- Parameters:
initialBufferSize
- The initial buffer size
-
setLogLevel
public void setLogLevel(io.netty.handler.logging.LogLevel logLevel) Sets the Netty log level.- Parameters:
logLevel
- The log level
-
setCompressionThreshold
Sets the minimum size of a request body must be in order to be compressed. Default value (1024).- Parameters:
compressionThreshold
- The size request bodies must be in order to be a candidate for compression.
-
setCompressionLevel
Sets the compression level (0-9). Default value (6).- Parameters:
compressionLevel
- The compression level.
-
setKeepAliveOnServerError
public void setKeepAliveOnServerError(boolean keepAliveOnServerError) Whether to send connection keep alive on internal server errors. Default value (true).- Parameters:
keepAliveOnServerError
- The keep alive on server error flag
-
getPcapLoggingPathPattern
The path pattern to use for logging incoming connections to pcap. This is an unsupported option: Behavior may change, or it may disappear entirely, without notice!- Returns:
- The path pattern, or
null
if logging is disabled.
-
setPcapLoggingPathPattern
The path pattern to use for logging incoming connections to pcap. This is an unsupported option: Behavior may change, or it may disappear entirely, without notice!- Parameters:
pcapLoggingPathPattern
- The path pattern, ornull
to disable logging.
-
getListeners
Get the explicit netty listener configurations, ornull
if they should be implicit.- Returns:
- The listeners
-
setListeners
Set the explicit netty listener configurations, ornull
if they should be implicit.- Parameters:
listeners
- The listeners
-
isEagerParsing
public boolean isEagerParsing()Parse incoming JSON data eagerly, before route binding. Default value false.- Returns:
- Whether to parse incoming JSON data eagerly before route binding
- Since:
- 4.0.0
-
setEagerParsing
public void setEagerParsing(boolean eagerParsing) Parse incoming JSON data eagerly, before route binding. Default value false.- Parameters:
eagerParsing
- Whether to parse incoming JSON data eagerly before route binding- Since:
- 4.0.0
-
getJsonBufferMaxComponents
public int getJsonBufferMaxComponents()Maximum number of buffers to keep around in JSON parsing before they should be consolidated. Defaults to 4096.- Returns:
- The maximum number of components
- Since:
- 4.0.0
-
setJsonBufferMaxComponents
public void setJsonBufferMaxComponents(int jsonBufferMaxComponents) Maximum number of buffers to keep around in JSON parsing before they should be consolidated. Defaults to 4096.- Parameters:
jsonBufferMaxComponents
- The maximum number of components- Since:
- 4.0.0
-
isLegacyMultiplexHandlers
public boolean isLegacyMultiplexHandlers()Prior to 4.4.0, the Micronaut HTTP server used a multi-pipeline approach for handling HTTP/2 connections where every request got its own netty pipeline with HTTP/2 to HTTP/1.1 converters on the pipeline. This allowed for using mostly unchanged HTTP/1.1 in the request handling and anyNettyServerCustomizer
s.As of 4.4.0, this approach was replaced with a more performant HTTP/2-specific implementation. This means worse compatibility with HTTP/1.1-based code paths and customizers, however. Setting this option to
true
returns to the old behavior.- Returns:
- Whether to enable the legacy multi-pipeline multiplex handlers for HTTP/2 connections
-
setLegacyMultiplexHandlers
public void setLegacyMultiplexHandlers(boolean legacyMultiplexHandlers) Prior to 4.4.0, the Micronaut HTTP server used a multi-pipeline approach for handling HTTP/2 connections where every request got its own netty pipeline with HTTP/2 to HTTP/1.1 converters on the pipeline. This allowed for using mostly unchanged HTTP/1.1 in the request handling and anyNettyServerCustomizer
s.As of 4.4.0, this approach was replaced with a more performant HTTP/2-specific implementation. This means worse compatibility with HTTP/1.1-based code paths and customizers, however. Setting this option to
true
returns to the old behavior.- Parameters:
legacyMultiplexHandlers
- Whether to enable the legacy multi-pipeline multiplex handlers for HTTP/2 connections
-