Class HTTPServerConfiguration

java.lang.Object
io.fusionauth.http.server.HTTPServerConfiguration
All Implemented Interfaces:
Configurable<HTTPServerConfiguration>

public class HTTPServerConfiguration extends Object implements Configurable<HTTPServerConfiguration>
The HTTP Server configuration.
Author:
Brian Pontarelli
  • Constructor Details

    • HTTPServerConfiguration

      public HTTPServerConfiguration()
  • Method Details

    • configuration

      public HTTPServerConfiguration configuration()
      Specified by:
      configuration in interface Configurable<HTTPServerConfiguration>
      Returns:
      This.
    • getBaseDir

      public Path getBaseDir()
      Returns:
      The base dir for the entire server. This can be used to calculate files from as needed.
    • getContextPath

      public String getContextPath()
      Returns:
      The context page that the entire server serves requests under or null.
    • getExpectValidator

      public ExpectValidator getExpectValidator()
      Returns:
      The expect validator or null.
    • getHandler

      public HTTPHandler getHandler()
      Returns:
      The HTTP handler for this server. Cannot be null and is required.
    • getInitialReadTimeoutDuration

      public Duration getInitialReadTimeoutDuration()
      Returns:
      The timeout between a socket being accepted by the server and the first byte being read. This is distinct and separate from the timeout for subsequent reads after the connection has been "kept alive".
    • getInstrumenter

      public Instrumenter getInstrumenter()
      Returns:
      The instrumenter or null.
    • getKeepAliveTimeoutDuration

      public Duration getKeepAliveTimeoutDuration()
      Returns:
      The timeout between requests when the server is in Keep-Alive mode. This is the maximum value to prevent DoS attacks that use the HTTP headers to set extremely long timeouts.
    • getListeners

      public List<HTTPListenerConfiguration> getListeners()
      Returns:
      All configured listeners (if any) or an empty list.
    • getLoggerFactory

      public LoggerFactory getLoggerFactory()
      Returns:
      The logger factory.
    • getMaxResponseChunkSize

      public int getMaxResponseChunkSize()
      Returns:
      The max chunk size in the response. Defaults to 16k bytes.
    • getMinimumReadThroughput

      public long getMinimumReadThroughput()
      This configuration is the minimum number of bytes per second that a client must send a request to the server before the server closes the connection.
      Returns:
      The minimum throughput for any connection with the server in bytes per second.
    • getMinimumWriteThroughput

      public long getMinimumWriteThroughput()
      This configuration is the minimum number of bytes per second that a client must read the response from the server before the server closes the connection.
      Returns:
      The minimum throughput for any connection with the server in bytes per second.
    • getMultipartBufferSize

      public int getMultipartBufferSize()
      Returns:
      The multipart buffer size in bytes. This is primary used for parsing multipart requests by the HTTPRequest class. Defaults to 16k bytes.
    • getProcessingTimeoutDuration

      public Duration getProcessingTimeoutDuration()
      Returns:
      The timeout between when the request has been fully read and the first byte is written. This provides the worker thread to perform work before it begins to write. This timeout should be relatively short depending on how long you want the browser/client to wait before the response comes back. Defaults to 10 seconds.
    • getReadThroughputCalculationDelay

      public Duration getReadThroughputCalculationDelay()
      Returns:
      the duration that will be used to delay the calculation and enforcement of the minimum read throughput.
    • getRequestBufferSize

      public int getRequestBufferSize()
      Returns:
      The size of the buffer used to read the request. This defaults to 16k bytes.
    • getResponseBufferSize

      public int getResponseBufferSize()
      Returns:
      The size of the buffer used to store the response. This allows the server to handle exceptions and errors without writing back a 200 response that is actually an error. This defaults to 64k bytes.
    • getShutdownDuration

      public Duration getShutdownDuration()
      Returns:
      The duration that the server will wait while worker threads complete before forcibly shutting itself down. Defaults to 10 seconds.
    • getWriteThroughputCalculationDelay

      public Duration getWriteThroughputCalculationDelay()
      Returns:
      the duration that will be used to delay the calculation and enforcement of the minimum write throughput.
    • isCompressByDefault

      public boolean isCompressByDefault()
      Returns:
      Whether all responses are compressed by default. Defaults to true.
    • withBaseDir

      public HTTPServerConfiguration withBaseDir(Path baseDir)
      Sets the base directory for this server. This is passed to the HTTPContext, which is available from this class. This defaults to the current working directory of the process.
      Specified by:
      withBaseDir in interface Configurable<HTTPServerConfiguration>
      Parameters:
      baseDir - The base dir.
      Returns:
      This.
    • withCompressByDefault

      public HTTPServerConfiguration withCompressByDefault(boolean compressByDefault)
      Sets the default compression behavior for the HTTP response. This behavior can be optionally set per response. See HTTPResponse.setCompress(boolean). Defaults to true.
      Specified by:
      withCompressByDefault in interface Configurable<HTTPServerConfiguration>
      Parameters:
      compressByDefault - true if you want to compress by default, or false to not compress by default.
      Returns:
      This.
    • withContextPath

      public HTTPServerConfiguration withContextPath(String contextPath)
      Sets the prefix of the URIs that this server handles. Technically, the server will accept all inbound connections, but if a context path is set, it can assist the application with building URIs (in HTML for example). This value will be accessible via the HTTPRequest.getContextPath() method.
      Specified by:
      withContextPath in interface Configurable<HTTPServerConfiguration>
      Parameters:
      contextPath - The context path for the server.
      Returns:
      This.
    • withExpectValidator

      public HTTPServerConfiguration withExpectValidator(ExpectValidator validator)
      Sets an ExpectValidator that is used if a client sends the server a Expect: 100-continue header.
      Specified by:
      withExpectValidator in interface Configurable<HTTPServerConfiguration>
      Parameters:
      validator - The validator.
      Returns:
      This.
    • withHandler

      public HTTPServerConfiguration withHandler(HTTPHandler handler)
      Sets the handler that will process the requests.
      Specified by:
      withHandler in interface Configurable<HTTPServerConfiguration>
      Parameters:
      handler - The handler that processes the requests.
      Returns:
      This.
    • withInitialReadTimeout

      public HTTPServerConfiguration withInitialReadTimeout(Duration duration)
      Sets the duration that the server will attempt to read the first byte from a client. This is the very first byte after the socket connection has been accepted by the server. Defaults to 2 seconds.
      Specified by:
      withInitialReadTimeout in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withInstrumenter

      public HTTPServerConfiguration withInstrumenter(Instrumenter instrumenter)
      Sets an instrumenter that the server will notify when events and conditions happen.
      Specified by:
      withInstrumenter in interface Configurable<HTTPServerConfiguration>
      Parameters:
      instrumenter - The instrumenter.
      Returns:
      This.
    • withKeepAliveTimeoutDuration

      public HTTPServerConfiguration withKeepAliveTimeoutDuration(Duration duration)
      Sets the duration that the server will allow client connections to remain open and idle after each request has been processed. This is the Keep-Alive state before the first byte of the next request is read. Defaults to 20 seconds.
      Specified by:
      withKeepAliveTimeoutDuration in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withListener

      public HTTPServerConfiguration withListener(HTTPListenerConfiguration listener)
      Adds a listener configuration for the server. This will listen on the address and port of the configuration but will share the thread pool of the server.
      Specified by:
      withListener in interface Configurable<HTTPServerConfiguration>
      Parameters:
      listener - The listener.
      Returns:
      This.
    • withLoggerFactory

      public HTTPServerConfiguration withLoggerFactory(LoggerFactory loggerFactory)
      Sets the logger factory that all the HTTP server classes use to retrieve specific loggers. Defaults to the SystemOutLoggerFactory.
      Specified by:
      withLoggerFactory in interface Configurable<HTTPServerConfiguration>
      Parameters:
      loggerFactory - The factory.
      Returns:
      This.
    • withMaxResponseChunkSize

      public HTTPServerConfiguration withMaxResponseChunkSize(int size)
      This configures the maximum size of a chunk in the response when the server is using chunked response encoding. Defaults to 16k.
      Specified by:
      withMaxResponseChunkSize in interface Configurable<HTTPServerConfiguration>
      Parameters:
      size - The size in bytes.
      Returns:
      This.
    • withMinimumReadThroughput

      public HTTPServerConfiguration withMinimumReadThroughput(long bytesPerSecond)
      This configures the minimum number of bytes per second that a client must send a request to the server before the server closes the connection. Set this to -1 to disable this check.
      Specified by:
      withMinimumReadThroughput in interface Configurable<HTTPServerConfiguration>
      Parameters:
      bytesPerSecond - The bytes per second throughput.
      Returns:
      This.
    • withMinimumWriteThroughput

      public HTTPServerConfiguration withMinimumWriteThroughput(long bytesPerSecond)
      This configures the minimum number of bytes per second that a client must read the response from the server before the server closes the connection. Set this to -1 to disable this check.
      Specified by:
      withMinimumWriteThroughput in interface Configurable<HTTPServerConfiguration>
      Parameters:
      bytesPerSecond - The bytes per second throughput.
      Returns:
      This.
    • withMultipartBufferSize

      public HTTPServerConfiguration withMultipartBufferSize(int multipartBufferSize)
      Sets the size of the buffer that is used to process the multipart request body. This defaults to 16k.
      Specified by:
      withMultipartBufferSize in interface Configurable<HTTPServerConfiguration>
      Parameters:
      multipartBufferSize - The size of the buffer.
      Returns:
      This.
    • withProcessingTimeoutDuration

      public HTTPServerConfiguration withProcessingTimeoutDuration(Duration duration)
      Sets the duration that the server will allow worker threads to run after the final request byte is read and before the first response byte is written. Defaults to 10 seconds.
      Specified by:
      withProcessingTimeoutDuration in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withReadThroughputCalculationDelayDuration

      public HTTPServerConfiguration withReadThroughputCalculationDelayDuration(Duration duration)
      This configures the duration of the initial delay before calculating and enforcing the minimum read throughput. Defaults to 5 seconds.

      This accounts for some warm up period, and exempts short-lived connections that may have smaller payloads that are more difficult to calculate a reasonable minimum read throughput.

      Specified by:
      withReadThroughputCalculationDelayDuration in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration to delay the enforcement of the minimum read throughput.
      Returns:
      This.
    • withRequestBufferSize

      public HTTPServerConfiguration withRequestBufferSize(int requestBufferSize)
      Sets the size of the buffer that is used to process the HTTP request. This defaults to 16k.
      Specified by:
      withRequestBufferSize in interface Configurable<HTTPServerConfiguration>
      Parameters:
      requestBufferSize - The size of the buffer.
      Returns:
      This.
    • withResponseBufferSize

      public HTTPServerConfiguration withResponseBufferSize(int responseBufferSize)
      Sets the size of the buffer that is used to store the HTTP response before any bytes are written back to the client. This is useful when the server is generating the response but encounters an error. In this case, the server will throw out the response and change to a 500 error response. This defaults to 64k. Negative values disable the response buffer.
      Specified by:
      withResponseBufferSize in interface Configurable<HTTPServerConfiguration>
      Parameters:
      responseBufferSize - The size of the buffer. Set to -1 to disable buffering completely.
      Returns:
      This.
    • withShutdownDuration

      public HTTPServerConfiguration withShutdownDuration(Duration duration)
      Sets the duration the server will wait for running requests to be completed. Defaults to 10 seconds.
      Specified by:
      withShutdownDuration in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration the server will wait for all running request processing threads to complete their work.
      Returns:
      This.
    • withWriteThroughputCalculationDelayDuration

      public HTTPServerConfiguration withWriteThroughputCalculationDelayDuration(Duration duration)
      This configures the duration of the initial delay before calculating and enforcing the minimum write throughput. Defaults to 5 seconds.

      This accounts for some warm up period, and exempts short-lived connections that may have smaller payloads that are more difficult to calculate a reasonable minimum write throughput.

      Specified by:
      withWriteThroughputCalculationDelayDuration in interface Configurable<HTTPServerConfiguration>
      Parameters:
      duration - The duration to delay the enforcement of the minimum write throughput.
      Returns:
      This.