Package io.micronaut.http.server
Class HttpServerConfiguration
- java.lang.Object
-
- io.micronaut.http.server.HttpServerConfiguration
-
- All Implemented Interfaces:
io.micronaut.http.context.ServerContextPathProvider
@ConfigurationProperties(value="micronaut.server", cliPrefix="") public class HttpServerConfiguration extends java.lang.Object implements io.micronaut.http.context.ServerContextPathProviderA base
ConfigurationPropertiesfor servers.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpServerConfiguration.CorsConfigurationConfiguration for CORS.static classHttpServerConfiguration.HostResolutionConfigurationConfiguration for host resolution with theHttpHostResolver.static classHttpServerConfiguration.HttpLocaleResolutionConfigurationPropertiesConfiguration for locale resolution used byHttpLocaleResolver.static classHttpServerConfiguration.MultipartConfigurationConfiguration for multipart handling.
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_DATEHEADERThe default date header.static booleanDEFAULT_DUAL_PROTOCOLThe default value for enabling dual protocol (http/https).static booleanDEFAULT_HTTP_TO_HTTPS_REDIRECTThe default value for redirect HTTP to HTTPS when using dual protocal.static longDEFAULT_IDLE_TIME_MINUTESThe default idle time.static booleanDEFAULT_LOG_HANDLED_EXCEPTIONSThe default value for log handled exceptions.static longDEFAULT_MAX_REQUEST_SIZEThe default max request size.static intDEFAULT_PORTThe default port value.static intDEFAULT_RANDOM_PORTThe default value random port.static longDEFAULT_READ_IDLE_TIME_MINUTESThe default read idle time in minutes.static longDEFAULT_WRITE_IDLE_TIME_MINUTESThe default write idle time in minutes.static java.lang.StringPREFIXThe prefix used for configuration.
-
Constructor Summary
Constructors Constructor Description HttpServerConfiguration()Default constructor.HttpServerConfiguration(io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description io.micronaut.runtime.ApplicationConfigurationgetApplicationConfiguration()java.lang.StringgetClientAddressHeader()java.lang.StringgetContextPath()HttpServerConfiguration.CorsConfigurationgetCors()java.nio.charset.CharsetgetDefaultCharset()java.util.Optional<java.lang.String>getHost()HttpServerConfiguration.HostResolutionConfigurationgetHostResolution()io.micronaut.http.HttpVersiongetHttpVersion()The HTTP version to use.java.time.DurationgetIdleTimeout()HttpLocaleResolutionConfigurationgetLocaleResolution()longgetMaxRequestSize()HttpServerConfiguration.MultipartConfigurationgetMultipart()java.util.Optional<java.lang.Integer>getPort()java.time.DurationgetReadIdleTimeout()java.util.Optional<java.lang.Integer>getReadTimeout()Deprecated.This setting does nothingjava.util.Optional<java.lang.String>getServerHeader()io.micronaut.scheduling.executor.ThreadSelectiongetThreadSelection()java.time.DurationgetWriteIdleTimeout()booleanisDateHeader()booleanisDualProtocol()booleanisHttpToHttpsRedirect()booleanisLogHandledExceptions()voidsetClientAddressHeader(java.lang.String clientAddressHeader)voidsetContextPath(java.lang.String contextPath)Sets the context path for the web server.voidsetCors(HttpServerConfiguration.CorsConfiguration cors)Sets the cors configuration.voidsetDateHeader(boolean dateHeader)Sets whether a date header should be sent back.voidsetDefaultCharset(java.nio.charset.Charset defaultCharset)voidsetDualProtocol(boolean dualProtocol)voidsetHost(java.lang.String host)Sets the host to bind to.voidsetHostResolution(HttpServerConfiguration.HostResolutionConfiguration hostResolution)voidsetHttpToHttpsRedirect(boolean httpToHttpsRedirect)voidsetHttpVersion(io.micronaut.http.HttpVersion httpVersion)Sets the HTTP version to use.voidsetIdleTimeout(java.time.Duration idleTimeout)Sets the idle time of connections for the server.voidsetLocaleResolution(HttpServerConfiguration.HttpLocaleResolutionConfigurationProperties localeResolution)voidsetLogHandledExceptions(boolean logHandledExceptions)Sets whether exceptions handled by either an error route or exception handler should still be logged.voidsetMaxRequestSize(long maxRequestSize)Sets the maximum request size.voidsetMultipart(HttpServerConfiguration.MultipartConfiguration multipart)Sets the multipart configuration.voidsetPort(int port)Sets the port to bind to.voidsetReadIdleTimeout(java.time.Duration readIdleTimeout)Sets the amount of time a connection can remain idle without any reads occurring.voidsetReadTimeout(java.lang.Integer readTimeout)Deprecated.This setting does nothingvoidsetServerHeader(java.lang.String serverHeader)Sets the name of the server header.voidsetThreadSelection(io.micronaut.scheduling.executor.ThreadSelection threadSelection)Sets theThreadSelectionmodel to use for the server.voidsetWriteIdleTimeout(java.time.Duration writeIdleTimeout)Sets the amount of time a connection can remain idle without any writes occurring.
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
The default port value.- See Also:
- Constant Field Values
-
PREFIX
public static final java.lang.String PREFIX
The prefix used for configuration.- See Also:
- Constant Field Values
-
DEFAULT_RANDOM_PORT
public static final int DEFAULT_RANDOM_PORT
The default value random port.- See Also:
- Constant Field Values
-
DEFAULT_MAX_REQUEST_SIZE
public static final long DEFAULT_MAX_REQUEST_SIZE
The default max request size.- See Also:
- Constant Field Values
-
DEFAULT_READ_IDLE_TIME_MINUTES
public static final long DEFAULT_READ_IDLE_TIME_MINUTES
The default read idle time in minutes.- See Also:
- Constant Field Values
-
DEFAULT_WRITE_IDLE_TIME_MINUTES
public static final long DEFAULT_WRITE_IDLE_TIME_MINUTES
The default write idle time in minutes.- See Also:
- Constant Field Values
-
DEFAULT_DATEHEADER
public static final boolean DEFAULT_DATEHEADER
The default date header.- See Also:
- Constant Field Values
-
DEFAULT_IDLE_TIME_MINUTES
public static final long DEFAULT_IDLE_TIME_MINUTES
The default idle time.- See Also:
- Constant Field Values
-
DEFAULT_LOG_HANDLED_EXCEPTIONS
public static final boolean DEFAULT_LOG_HANDLED_EXCEPTIONS
The default value for log handled exceptions.- See Also:
- Constant Field Values
-
DEFAULT_DUAL_PROTOCOL
public static final boolean DEFAULT_DUAL_PROTOCOL
The default value for enabling dual protocol (http/https).- See Also:
- Constant Field Values
-
DEFAULT_HTTP_TO_HTTPS_REDIRECT
public static final boolean DEFAULT_HTTP_TO_HTTPS_REDIRECT
The default value for redirect HTTP to HTTPS when using dual protocal.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpServerConfiguration
public HttpServerConfiguration()
Default constructor.
-
HttpServerConfiguration
@Inject public HttpServerConfiguration(io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
- Parameters:
applicationConfiguration- The application configuration
-
-
Method Detail
-
getHttpVersion
public io.micronaut.http.HttpVersion getHttpVersion()
The HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Returns:
- The http version
-
setHttpVersion
public void setHttpVersion(io.micronaut.http.HttpVersion httpVersion)
Sets the HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Parameters:
httpVersion- The http version
-
getThreadSelection
@NonNull public io.micronaut.scheduling.executor.ThreadSelection getThreadSelection()
- Returns:
- The
ThreadSelectionmodel to use for the server.
-
setThreadSelection
public void setThreadSelection(io.micronaut.scheduling.executor.ThreadSelection threadSelection)
Sets theThreadSelectionmodel to use for the server. Default value MANUAL.- Parameters:
threadSelection- The thread selection model
-
getApplicationConfiguration
public io.micronaut.runtime.ApplicationConfiguration getApplicationConfiguration()
- Returns:
- The application configuration instance
-
getDefaultCharset
public java.nio.charset.Charset getDefaultCharset()
- Returns:
- The default charset to use
-
getPort
public java.util.Optional<java.lang.Integer> getPort()
- Returns:
- The default server port
-
getHost
public java.util.Optional<java.lang.String> getHost()
- Returns:
- The default host
-
getReadTimeout
@Deprecated public java.util.Optional<java.lang.Integer> getReadTimeout()
Deprecated.This setting does nothing- Returns:
- The read timeout setting for the server
-
getMultipart
public HttpServerConfiguration.MultipartConfiguration getMultipart()
- Returns:
- Configuration for multipart / file uploads
-
getCors
public HttpServerConfiguration.CorsConfiguration getCors()
- Returns:
- Configuration for CORS
-
getMaxRequestSize
public long getMaxRequestSize()
- Returns:
- The maximum request body size
-
getReadIdleTimeout
public java.time.Duration getReadIdleTimeout()
- Returns:
- The default amount of time to allow read operation connections to remain idle
-
getWriteIdleTimeout
public java.time.Duration getWriteIdleTimeout()
- Returns:
- The default amount of time to allow write operation connections to remain idle
-
getIdleTimeout
public java.time.Duration getIdleTimeout()
- Returns:
- The time to allow an idle connection for
-
getServerHeader
public java.util.Optional<java.lang.String> getServerHeader()
- Returns:
- The optional server header value
-
isDateHeader
public boolean isDateHeader()
- Returns:
- True if the date header should be set
-
isLogHandledExceptions
public boolean isLogHandledExceptions()
- Returns:
- True if exceptions handled by either an error route or exception handler should be logged
-
getHostResolution
@Nullable public HttpServerConfiguration.HostResolutionConfiguration getHostResolution()
- Returns:
- The host resolution configuration
-
getLocaleResolution
@Nullable public HttpLocaleResolutionConfiguration getLocaleResolution()
- Returns:
- The host resolution configuration
-
getClientAddressHeader
public java.lang.String getClientAddressHeader()
- Returns:
- Which header stores the original client
-
getContextPath
public java.lang.String getContextPath()
- Specified by:
getContextPathin interfaceio.micronaut.http.context.ServerContextPathProvider- Returns:
- the context path for the web server
-
isDualProtocol
public boolean isDualProtocol()
- Returns:
- if dual protocol has been enabled or not
-
isHttpToHttpsRedirect
public boolean isHttpToHttpsRedirect()
- Returns:
- if redirection from HTTP to HTTPS is enabled or not
-
setDefaultCharset
public void setDefaultCharset(java.nio.charset.Charset defaultCharset)
- Parameters:
defaultCharset- The default charset to use
-
setPort
public void setPort(int port)
Sets the port to bind to. Default value (-1)- Parameters:
port- The port
-
setHost
public void setHost(java.lang.String host)
Sets the host to bind to.- Parameters:
host- The host
-
setReadTimeout
@Deprecated public void setReadTimeout(java.lang.Integer readTimeout)
Deprecated.This setting does nothingSets the default read timeout.- Parameters:
readTimeout- The read timeout
-
setServerHeader
public void setServerHeader(java.lang.String serverHeader)
Sets the name of the server header.- Parameters:
serverHeader- The server header
-
setMaxRequestSize
public void setMaxRequestSize(@ReadableBytes long maxRequestSize)Sets the maximum request size. Default value (10485760L => // 10MB)- Parameters:
maxRequestSize- The max request size
-
setReadIdleTimeout
public void setReadIdleTimeout(java.time.Duration readIdleTimeout)
Sets the amount of time a connection can remain idle without any reads occurring. Default value (5L minutes).- Parameters:
readIdleTimeout- The read idle time
-
setWriteIdleTimeout
public void setWriteIdleTimeout(java.time.Duration writeIdleTimeout)
Sets the amount of time a connection can remain idle without any writes occurring. Default value (5L minutes).- Parameters:
writeIdleTimeout- The write idle time
-
setIdleTimeout
public void setIdleTimeout(java.time.Duration idleTimeout)
Sets the idle time of connections for the server. Default value (5L minutes).- Parameters:
idleTimeout- The idle time
-
setMultipart
public void setMultipart(HttpServerConfiguration.MultipartConfiguration multipart)
Sets the multipart configuration.- Parameters:
multipart- The multipart configuration
-
setCors
public void setCors(HttpServerConfiguration.CorsConfiguration cors)
Sets the cors configuration.- Parameters:
cors- The cors configuration
-
setDateHeader
public void setDateHeader(boolean dateHeader)
Sets whether a date header should be sent back. Default value (true).- Parameters:
dateHeader- True if a date header should be sent.
-
setLogHandledExceptions
public void setLogHandledExceptions(boolean logHandledExceptions)
Sets whether exceptions handled by either an error route or exception handler should still be logged. Default value (false).- Parameters:
logHandledExceptions- True if exceptions should be logged
-
setHostResolution
public void setHostResolution(HttpServerConfiguration.HostResolutionConfiguration hostResolution)
- Parameters:
hostResolution- The host resolution configuration
-
setLocaleResolution
public void setLocaleResolution(HttpServerConfiguration.HttpLocaleResolutionConfigurationProperties localeResolution)
- Parameters:
localeResolution- The locale resolution configuration
-
setClientAddressHeader
public void setClientAddressHeader(java.lang.String clientAddressHeader)
- Parameters:
clientAddressHeader- The header that stores the original client address
-
setContextPath
public void setContextPath(java.lang.String contextPath)
Sets the context path for the web server.- Parameters:
contextPath- the context path for the web server
-
setDualProtocol
public void setDualProtocol(boolean dualProtocol)
- Parameters:
dualProtocol- the dual protocol (http/https) configuration. Default value (false).
-
setHttpToHttpsRedirect
public void setHttpToHttpsRedirect(boolean httpToHttpsRedirect)
- Parameters:
httpToHttpsRedirect- Set to true to enable redirecting all http requests to the same URL but with https instead. This should only be used whendualProtocolis enabled. Default value (false). This feature uses the host resolution capabilities to determine the host to redirect to.
-
-