Package io.micronaut.http.server
Class HttpServerConfiguration
java.lang.Object
io.micronaut.http.server.HttpServerConfiguration
- All Implemented Interfaces:
ServerContextPathProvider
- Direct Known Subclasses:
NettyHttpServerConfiguration
@ConfigurationProperties(value="micronaut.server",
cliPrefix="")
public class HttpServerConfiguration
extends Object
implements ServerContextPathProvider
A base ConfigurationProperties for servers.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for CORS.static classAllows configuration of properties for theio.micronaut.http.server.netty.body.AbstractFileBodyWriter.static classConfiguration for host resolution with theHttpHostResolver.static classConfiguration for locale resolution used byHttpLocaleResolver.static classConfiguration for multipart handling. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThe default date header.static final booleanThe default value whether to dispatch OPTIONS Requests.static final booleanThe default value for enabling dual protocol (http/https).static final booleanThe default value for redirect HTTP to HTTPS when using dual protocal.static final longThe default idle time.static final booleanThe default value for log handled exceptions.static final intstatic final longThe default max buffer size.static final longThe default max request size.static final intThe default port value.static final intThe default value random port.static final longThe default read idle time in minutes.static final booleanstatic final longThe default write idle time in minutes.static final StringThe prefix used for configuration. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HttpServerConfiguration(ApplicationConfiguration applicationConfiguration) -
Method Summary
Modifier and TypeMethodDescriptiongetCors()getHost()The HTTP version to use.intlonglonggetPort()Deprecated.This setting does nothingbooleanbooleanSet to true to dispatch OPTIONS requests.booleanbooleanBrowsers can send characters (such as|) which are not permitted under RFC 3986 as part of the request path.booleanbooleanbooleanbooleanReturns whether the semicolon is considered a normal character in the query.booleanDeprecated, for removal: This API element is subject to removal in a future version.URLs are always validated again as of 4.9.voidsetClientAddressHeader(String clientAddressHeader) voidsetContextPath(String contextPath) Sets the context path for the web server.voidSets the cors configuration.voidsetDateHeader(boolean dateHeader) Sets whether a date header should be sent back.voidsetDefaultCharset(Charset defaultCharset) voidsetDispatchOptionsRequests(boolean dispatchOptionsRequests) Set to true to dispatch OPTIONS requests.voidsetDualProtocol(boolean dualProtocol) voidsetEscapeHtmlUrl(boolean escapeHtmlUrl) Browsers can send characters (such as|) which are not permitted under RFC 3986 as part of the request path.voidSets the host to bind to.voidsetHostResolution(HttpServerConfiguration.HostResolutionConfiguration hostResolution) voidsetHttpToHttpsRedirect(boolean httpToHttpsRedirect) voidsetHttpVersion(HttpVersion httpVersion) Sets the HTTP version to use.voidsetIdleTimeout(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.voidsetMaxParams(int maxParams) voidsetMaxRequestBufferSize(long maxRequestBufferSize) Sets the maximum number of request bytes that will be buffered.voidsetMaxRequestSize(long maxRequestSize) Sets the maximum request size.voidSets the multipart configuration.voidsetNotFoundOnMissingBody(boolean notFoundOnMissingBody) voidsetPort(int port) Sets the port to bind to.voidsetReadIdleTimeout(Duration readIdleTimeout) Sets the amount of time a connection can remain idle without any reads occurring.voidsetReadTimeout(Integer readTimeout) Deprecated.This setting does nothingvoidsetSemicolonIsNormalChar(boolean semicolonIsNormalChar) Sets whether the semicolon should be considered a normal character in the query.voidsetServerHeader(String serverHeader) Sets the name of the server header.voidsetThreadSelection(ThreadSelection threadSelection) Sets theThreadSelectionmodel to use for the server.voidsetValidateUrl(boolean validateUrl) Deprecated, for removal: This API element is subject to removal in a future version.URLs are always validated again as of 4.9.voidsetWriteIdleTimeout(Duration writeIdleTimeout) Sets the amount of time a connection can remain idle without any writes occurring.
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe default port value.- See Also:
-
PREFIX
The prefix used for configuration.- See Also:
-
DEFAULT_RANDOM_PORT
public static final int DEFAULT_RANDOM_PORTThe default value random port.- See Also:
-
DEFAULT_MAX_REQUEST_SIZE
public static final long DEFAULT_MAX_REQUEST_SIZEThe default max request size.- See Also:
-
DEFAULT_MAX_REQUEST_BUFFER_SIZE
public static final long DEFAULT_MAX_REQUEST_BUFFER_SIZEThe default max buffer size.- See Also:
-
DEFAULT_READ_IDLE_TIME_MINUTES
public static final long DEFAULT_READ_IDLE_TIME_MINUTESThe default read idle time in minutes.- See Also:
-
DEFAULT_WRITE_IDLE_TIME_MINUTES
public static final long DEFAULT_WRITE_IDLE_TIME_MINUTESThe default write idle time in minutes.- See Also:
-
DEFAULT_DATEHEADER
public static final boolean DEFAULT_DATEHEADERThe default date header.- See Also:
-
DEFAULT_IDLE_TIME_MINUTES
public static final long DEFAULT_IDLE_TIME_MINUTESThe default idle time.- See Also:
-
DEFAULT_LOG_HANDLED_EXCEPTIONS
public static final boolean DEFAULT_LOG_HANDLED_EXCEPTIONSThe default value for log handled exceptions.- See Also:
-
DEFAULT_DUAL_PROTOCOL
public static final boolean DEFAULT_DUAL_PROTOCOLThe default value for enabling dual protocol (http/https).- See Also:
-
DEFAULT_HTTP_TO_HTTPS_REDIRECT
public static final boolean DEFAULT_HTTP_TO_HTTPS_REDIRECTThe default value for redirect HTTP to HTTPS when using dual protocal.- See Also:
-
DEFAULT_DISPATCH_OPTIONS_REQUESTS
public static final boolean DEFAULT_DISPATCH_OPTIONS_REQUESTSThe default value whether to dispatch OPTIONS Requests.- See Also:
-
DEFAULT_SEMICOLON_IS_NORMAL_CHAR
public static final boolean DEFAULT_SEMICOLON_IS_NORMAL_CHAR- See Also:
-
DEFAULT_MAX_PARAMS
public static final int DEFAULT_MAX_PARAMS- See Also:
-
-
Constructor Details
-
HttpServerConfiguration
public HttpServerConfiguration()Default constructor. -
HttpServerConfiguration
- Parameters:
applicationConfiguration- The application configuration
-
-
Method Details
-
getHttpVersion
The HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Returns:
- The http version
-
setHttpVersion
Sets the HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Parameters:
httpVersion- The http version
-
getThreadSelection
- Returns:
- The
ThreadSelectionmodel to use for the server.
-
setThreadSelection
Sets theThreadSelectionmodel to use for the server. Default value MANUAL.- Parameters:
threadSelection- The thread selection model
-
getApplicationConfiguration
- Returns:
- The application configuration instance
-
getDefaultCharset
- Returns:
- The default charset to use
-
getPort
- Returns:
- The default server port
-
getHost
- Returns:
- The default host
-
getReadTimeout
Deprecated.This setting does nothing- Returns:
- The read timeout setting for the server
-
getMultipart
- Returns:
- Configuration for multipart / file uploads
-
getCors
- Returns:
- Configuration for CORS
-
getMaxRequestSize
public long getMaxRequestSize()- Returns:
- The maximum request body size
-
getMaxRequestBufferSize
public long getMaxRequestBufferSize()- Returns:
- The maximum number of bytes from the request that may be buffered if the application requests buffering
-
getReadIdleTimeout
- Returns:
- The default amount of time to allow read operation connections to remain idle
-
getWriteIdleTimeout
- Returns:
- The default amount of time to allow to write operation connections to remain idle
-
getIdleTimeout
- Returns:
- The time to allow an idle connection for
-
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
- Returns:
- The host resolution configuration
-
getLocaleResolution
- Returns:
- The host resolution configuration
-
getClientAddressHeader
- Returns:
- Which header stores the original client
-
getContextPath
- Specified by:
getContextPathin interfaceServerContextPathProvider- 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
-
isDispatchOptionsRequests
public boolean isDispatchOptionsRequests()Set to true to dispatch OPTIONS requests. Default value (false.- Returns:
- Whether OPTIONS requests should be dispatched.
- Since:
- 4.2.0
-
setDefaultCharset
- 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
Sets the host to bind to.- Parameters:
host- The host
-
setReadTimeout
Deprecated.This setting does nothingSets the default read timeout.- Parameters:
readTimeout- The read timeout
-
setServerHeader
Sets the name of the server header.- Parameters:
serverHeader- The server header
-
setMaxRequestSize
Sets the maximum request size. Default value (10485760L => // 10MB)- Parameters:
maxRequestSize- The max request size
-
setMaxRequestBufferSize
Sets the maximum number of request bytes that will be buffered. Fully streamed requests can still exceed this value. Default value (10485760L => // 10MB). Currently limited to2^31, if you need longer request bodies, stream them.
Note that there is always some internal buffering, so a very low value (< ~64K) will essentially act like a request size limit.- Parameters:
maxRequestBufferSize- The maximum number of bytes from the request that may be buffered if the application requests buffering
-
setReadIdleTimeout
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
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
Sets the idle time of connections for the server. Default value (5L minutes).- Parameters:
idleTimeout- The idle time
-
setMultipart
Sets the multipart configuration.- Parameters:
multipart- The multipart configuration
-
setCors
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
- Parameters:
hostResolution- The host resolution configuration
-
setLocaleResolution
public void setLocaleResolution(HttpServerConfiguration.HttpLocaleResolutionConfigurationProperties localeResolution) - Parameters:
localeResolution- The locale resolution configuration
-
setClientAddressHeader
- Parameters:
clientAddressHeader- The header that stores the original client address
-
setContextPath
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.
-
setDispatchOptionsRequests
public void setDispatchOptionsRequests(boolean dispatchOptionsRequests) Set to true to dispatch OPTIONS requests. Default value (false.- Parameters:
dispatchOptionsRequests- Set to true to dispatch OPTIONS requests.- Since:
- 4.2.0
-
setValidateUrl
Deprecated, for removal: This API element is subject to removal in a future version.URLs are always validated again as of 4.9. This setting does nothingIf the url should be validated by converting it toURI.- Parameters:
validateUrl- The validate URL value- Since:
- 4.3.0
-
isValidateUrl
Deprecated, for removal: This API element is subject to removal in a future version.URLs are always validated again as of 4.9. This setting does nothing- Returns:
- True if the url should be validated
- Since:
- 4.3.0
-
isEscapeHtmlUrl
public boolean isEscapeHtmlUrl()Browsers can send characters (such as|) which are not permitted under RFC 3986 as part of the request path. These characters are normally rejected by the server. If this setting is enabled, the server will escape these characters before parsing them usingURIso that they are not rejected. Default off.- Returns:
- Whether to escape forbidden URL characters prior to parsing
- Since:
- 4.9.0
-
setEscapeHtmlUrl
public void setEscapeHtmlUrl(boolean escapeHtmlUrl) Browsers can send characters (such as|) which are not permitted under RFC 3986 as part of the request path. These characters are normally rejected by the server. If this setting is enabled, the server will escape these characters before parsing them usingURIso that they are not rejected. Default off.- Parameters:
escapeHtmlUrl- Whether to escape forbidden URL characters prior to parsing- Since:
- 4.9.0
-
isNotFoundOnMissingBody
public boolean isNotFoundOnMissingBody()- Returns:
- True if not-found should be returned on missing body. False to return an empty body.
- Since:
- 4.6
-
setNotFoundOnMissingBody
public void setNotFoundOnMissingBody(boolean notFoundOnMissingBody) - Parameters:
notFoundOnMissingBody- True if no found should be returned on missing body. False to return an empty body.- Since:
- 4.6
-
isSemicolonIsNormalChar
public boolean isSemicolonIsNormalChar()Returns whether the semicolon is considered a normal character in the query. A "normal" semicolon is one that is not used as a parameter separator.- Returns:
trueif the semicolon is a normal character,falseotherwise.- Since:
- 4.8
-
setSemicolonIsNormalChar
public void setSemicolonIsNormalChar(boolean semicolonIsNormalChar) Sets whether the semicolon should be considered a normal character in the query. A "normal" semicolon is one that is not used as a parameter separator.- Parameters:
semicolonIsNormalChar-trueif the semicolon should be a normal character,falseotherwise.- Since:
- 4.8
-
getMaxParams
public int getMaxParams()- Returns:
- the maximum parameter count.
- Since:
- 4.8
-
setMaxParams
public void setMaxParams(int maxParams) - Parameters:
maxParams- the maximum parameter count.- Since:
- 4.8
-