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
Modifier and TypeClassDescriptionstatic class
Configuration for CORS.static class
Configuration for host resolution with theHttpHostResolver
.static class
Configuration for locale resolution used byHttpLocaleResolver
.static class
Configuration for multipart handling. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
The default date header.static final boolean
The default value whether to dispatch OPTIONS Requests.static final boolean
The default value for enabling dual protocol (http/https).static final boolean
The default value for redirect HTTP to HTTPS when using dual protocal.static final long
The default idle time.static final boolean
The default value for log handled exceptions.static final long
The default max request size.static final int
The default port value.static final int
The default value random port.static final long
The default read idle time in minutes.static final long
The default write idle time in minutes.static final String
The prefix used for configuration. -
Constructor Summary
ConstructorDescriptionDefault constructor.HttpServerConfiguration
(ApplicationConfiguration applicationConfiguration) -
Method Summary
Modifier and TypeMethodDescriptiongetCors()
getHost()
The HTTP version to use.long
getPort()
Deprecated.This setting does nothingboolean
boolean
Set to true to dispatch OPTIONS requests.boolean
boolean
boolean
boolean
void
setClientAddressHeader
(String clientAddressHeader) void
setContextPath
(String contextPath) Sets the context path for the web server.void
Sets the cors configuration.void
setDateHeader
(boolean dateHeader) Sets whether a date header should be sent back.void
setDefaultCharset
(Charset defaultCharset) void
setDispatchOptionsRequests
(boolean dispatchOptionsRequests) Set to true to dispatch OPTIONS requests.void
setDualProtocol
(boolean dualProtocol) void
Sets the host to bind to.void
setHostResolution
(HttpServerConfiguration.HostResolutionConfiguration hostResolution) void
setHttpToHttpsRedirect
(boolean httpToHttpsRedirect) void
setHttpVersion
(HttpVersion httpVersion) Sets the HTTP version to use.void
setIdleTimeout
(Duration idleTimeout) Sets the idle time of connections for the server.void
setLocaleResolution
(HttpServerConfiguration.HttpLocaleResolutionConfigurationProperties localeResolution) void
setLogHandledExceptions
(boolean logHandledExceptions) Sets whether exceptions handled by either an error route or exception handler should still be logged.void
setMaxRequestSize
(long maxRequestSize) Sets the maximum request size.void
Sets the multipart configuration.void
setPort
(int port) Sets the port to bind to.void
setReadIdleTimeout
(Duration readIdleTimeout) Sets the amount of time a connection can remain idle without any reads occurring.void
setReadTimeout
(Integer readTimeout) Deprecated.This setting does nothingvoid
setServerHeader
(String serverHeader) Sets the name of the server header.void
setThreadSelection
(ThreadSelection threadSelection) Sets theThreadSelection
model to use for the server.void
setValidateUrl
(boolean validateUrl) If the url should be validated by converting it toURI
.void
setWriteIdleTimeout
(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_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:
-
-
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
ThreadSelection
model to use for the server.
-
setThreadSelection
Sets theThreadSelection
model 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
-
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:
getContextPath
in 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
-
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 whendualProtocol
is 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
public void setValidateUrl(boolean validateUrl) If the url should be validated by converting it toURI
.- Parameters:
validateUrl
- The validate URL value- Since:
- 4.3.0
-
isValidateUrl
public boolean isValidateUrl()- Returns:
- True if the url should be validated
- Since:
- 4.3.0
-