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
  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      The default port value.
      See Also:
    • PREFIX

      public static final String PREFIX
      The prefix used for configuration.
      See Also:
    • DEFAULT_RANDOM_PORT

      public static final int DEFAULT_RANDOM_PORT
      The default value random port.
      See Also:
    • DEFAULT_MAX_REQUEST_SIZE

      public static final long DEFAULT_MAX_REQUEST_SIZE
      The default max request size.
      See Also:
    • DEFAULT_MAX_REQUEST_BUFFER_SIZE

      public static final long DEFAULT_MAX_REQUEST_BUFFER_SIZE
      The default max buffer size.
      See Also:
    • DEFAULT_READ_IDLE_TIME_MINUTES

      public static final long DEFAULT_READ_IDLE_TIME_MINUTES
      The default read idle time in minutes.
      See Also:
    • DEFAULT_WRITE_IDLE_TIME_MINUTES

      public static final long DEFAULT_WRITE_IDLE_TIME_MINUTES
      The default write idle time in minutes.
      See Also:
    • DEFAULT_DATEHEADER

      public static final boolean DEFAULT_DATEHEADER
      The default date header.
      See Also:
    • DEFAULT_IDLE_TIME_MINUTES

      public static final long DEFAULT_IDLE_TIME_MINUTES
      The default idle time.
      See Also:
    • DEFAULT_LOG_HANDLED_EXCEPTIONS

      public static final boolean DEFAULT_LOG_HANDLED_EXCEPTIONS
      The default value for log handled exceptions.
      See Also:
    • DEFAULT_DUAL_PROTOCOL

      public static final boolean DEFAULT_DUAL_PROTOCOL
      The default value for enabling dual protocol (http/https).
      See Also:
    • 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:
    • DEFAULT_DISPATCH_OPTIONS_REQUESTS

      public static final boolean DEFAULT_DISPATCH_OPTIONS_REQUESTS
      The default value whether to dispatch OPTIONS Requests.
      See Also:
  • Constructor Details

    • HttpServerConfiguration

      public HttpServerConfiguration()
      Default constructor.
    • HttpServerConfiguration

      @Inject public HttpServerConfiguration(ApplicationConfiguration applicationConfiguration)
      Parameters:
      applicationConfiguration - The application configuration
  • Method Details

    • getHttpVersion

      public HttpVersion getHttpVersion()
      The HTTP version to use. Defaults to HttpVersion.HTTP_1_1.
      Returns:
      The http version
    • setHttpVersion

      public void setHttpVersion(HttpVersion httpVersion)
      Sets the HTTP version to use. Defaults to HttpVersion.HTTP_1_1.
      Parameters:
      httpVersion - The http version
    • getThreadSelection

      @NonNull public @NonNull ThreadSelection getThreadSelection()
      Returns:
      The ThreadSelection model to use for the server.
    • setThreadSelection

      public void setThreadSelection(ThreadSelection threadSelection)
      Sets the ThreadSelection model to use for the server. Default value MANUAL.
      Parameters:
      threadSelection - The thread selection model
    • getApplicationConfiguration

      public ApplicationConfiguration getApplicationConfiguration()
      Returns:
      The application configuration instance
    • getDefaultCharset

      public Charset getDefaultCharset()
      Returns:
      The default charset to use
    • getPort

      public Optional<Integer> getPort()
      Returns:
      The default server port
    • getHost

      public Optional<String> getHost()
      Returns:
      The default host
    • getReadTimeout

      @Deprecated public Optional<Integer> 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

      public Duration getReadIdleTimeout()
      Returns:
      The default amount of time to allow read operation connections to remain idle
    • getWriteIdleTimeout

      public Duration getWriteIdleTimeout()
      Returns:
      The default amount of time to allow to write operation connections to remain idle
    • getIdleTimeout

      public Duration getIdleTimeout()
      Returns:
      The time to allow an idle connection for
    • getServerHeader

      public Optional<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

      Returns:
      The host resolution configuration
    • getLocaleResolution

      Returns:
      The host resolution configuration
    • getClientAddressHeader

      public String getClientAddressHeader()
      Returns:
      Which header stores the original client
    • getContextPath

      public String getContextPath()
      Specified by:
      getContextPath in interface 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
    • 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

      public void setDefaultCharset(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(String host)
      Sets the host to bind to.
      Parameters:
      host - The host
    • setReadTimeout

      @Deprecated public void setReadTimeout(Integer readTimeout)
      Deprecated.
      This setting does nothing
      Sets the default read timeout.
      Parameters:
      readTimeout - The read timeout
    • setServerHeader

      public void setServerHeader(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
    • setMaxRequestBufferSize

      public void setMaxRequestBufferSize(@ReadableBytes long maxRequestBufferSize)
      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 to 2^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

      public void setReadIdleTimeout(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(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(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(String clientAddressHeader)
      Parameters:
      clientAddressHeader - The header that stores the original client address
    • setContextPath

      public void setContextPath(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 when dualProtocol 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 to URI.
      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