Interface Configurable<T extends Configurable<T>>

Type Parameters:
T - The type of configurable for casting.
All Known Implementing Classes:
HTTPServer, HTTPServerConfiguration

public interface Configurable<T extends Configurable<T>>
An interface that identifies something that is configurable. Mainly, this allows the HTTPServer to be configured or to be passed a configuration.
  • Method Details

    • configuration

      HTTPServerConfiguration configuration()
      Returns:
      The configuration object.
    • withBaseDir

      default T 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.
      Parameters:
      baseDir - The base dir.
      Returns:
      This.
    • withCompressByDefault

      default T 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.
      Parameters:
      compressByDefault - true if you want to compress by default, or false to not compress by default.
      Returns:
      This.
    • withContextPath

      default T 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.
      Parameters:
      contextPath - The context path for the server.
      Returns:
      This.
    • withExpectValidator

      default T withExpectValidator(ExpectValidator validator)
      Sets an ExpectValidator that is used if a client sends the server a Expect: 100-continue header.
      Parameters:
      validator - The validator.
      Returns:
      This.
    • withHandler

      default T withHandler(HTTPHandler handler)
      Sets the handler that will process the requests.
      Parameters:
      handler - The handler that processes the requests.
      Returns:
      This.
    • withInitialReadTimeout

      default T 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.
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withInstrumenter

      default T withInstrumenter(Instrumenter instrumenter)
      Sets an instrumenter that the server will notify when events and conditions happen.
      Parameters:
      instrumenter - The instrumenter.
      Returns:
      This.
    • withKeepAliveTimeoutDuration

      default T 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.
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withListener

      default T 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.
      Parameters:
      listener - The listener.
      Returns:
      This.
    • withLoggerFactory

      default T withLoggerFactory(LoggerFactory loggerFactory)
      Sets the logger factory that all the HTTP server classes use to retrieve specific loggers. Defaults to the SystemOutLoggerFactory.
      Parameters:
      loggerFactory - The factory.
      Returns:
      This.
    • withMaxResponseChunkSize

      default T 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.
      Parameters:
      size - The size in bytes.
      Returns:
      This.
    • withMinimumReadThroughput

      default T 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.
      Parameters:
      bytesPerSecond - The bytes per second throughput.
      Returns:
      This.
    • withMinimumWriteThroughput

      default T 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.
      Parameters:
      bytesPerSecond - The bytes per second throughput.
      Returns:
      This.
    • withMultipartBufferSize

      default T withMultipartBufferSize(int multipartBufferSize)
      Sets the size of the buffer that is used to process the multipart request body. This defaults to 16k.
      Parameters:
      multipartBufferSize - The size of the buffer.
      Returns:
      This.
    • withProcessingTimeoutDuration

      default T 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.
      Parameters:
      duration - The duration.
      Returns:
      This.
    • withReadThroughputCalculationDelayDuration

      default T 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.

      Parameters:
      duration - The duration to delay the enforcement of the minimum read throughput.
      Returns:
      This.
    • withRequestBufferSize

      default T withRequestBufferSize(int requestBufferSize)
      Sets the size of the buffer that is used to process the HTTP request. This defaults to 16k.
      Parameters:
      requestBufferSize - The size of the buffer.
      Returns:
      This.
    • withResponseBufferSize

      default T 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.
      Parameters:
      responseBufferSize - The size of the buffer. Set to -1 to disable buffering completely.
      Returns:
      This.
    • withShutdownDuration

      default T withShutdownDuration(Duration duration)
      Sets the duration the server will wait for running requests to be completed. Defaults to 10 seconds.
      Parameters:
      duration - The duration the server will wait for all running request processing threads to complete their work.
      Returns:
      This.
    • withWriteThroughputCalculationDelayDuration

      default T 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.

      Parameters:
      duration - The duration to delay the enforcement of the minimum write throughput.
      Returns:
      This.