Class 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.ServerContextPathProvider

    A base ConfigurationProperties for servers.

    Since:
    1.0
    • 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 to HttpVersion.HTTP_1_1.
        Returns:
        The http version
      • setHttpVersion

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

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

        public void setThreadSelection​(io.micronaut.scheduling.executor.ThreadSelection threadSelection)
        Sets the ThreadSelection model 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
      • 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
      • getClientAddressHeader

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

        public java.lang.String getContextPath()
        Specified by:
        getContextPath in interface io.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 nothing
        Sets 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
      • 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
      • 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 when dualProtocol is enabled. Default value (false). This feature uses the host resolution capabilities to determine the host to redirect to.