Interface Configurable<T extends Configurable<T>>
- Type Parameters:
T- The type of configurable for casting.
- All Known Implementing Classes:
HTTPServer,HTTPServerConfiguration
-
Method Summary
Modifier and TypeMethodDescriptiondefault TwithBaseDir(Path baseDir) Sets the base directory for this server.default TwithChunkedBufferSize(int chunkedBufferSize) Sets the buffer size for the chunked input stream.default TwithCompressByDefault(boolean compressByDefault) Sets the default compression behavior for the HTTP response.default TwithContextPath(String contextPath) Sets the prefix of the URIs that this server handles.default TwithExpectValidator(ExpectValidator validator) Sets an ExpectValidator that is used if a client sends the server aExpect: 100-continueheader.default TwithHandler(HTTPHandler handler) Sets the handler that will process the requests.default TwithInitialReadTimeout(Duration duration) Sets the duration that the server will attempt to read the first byte from a client.default TwithInstrumenter(Instrumenter instrumenter) Sets an instrumenter that the server will notify when events and conditions happen.default TwithKeepAliveTimeoutDuration(Duration duration) Sets the duration that the server will allow client connections to remain open and idle after each request has been processed.default TwithListener(HTTPListenerConfiguration listener) Adds a listener configuration for the server.default TwithLoggerFactory(LoggerFactory loggerFactory) Sets the logger factory that all the HTTP server classes use to retrieve specific loggers.default TwithMaximumBytesToDrain(int maxBytesToDrain) Sets the maximum number of bytes the server will allow worker threads to drain after calling the request handler.default TwithMaxPendingSocketConnections(int maxPendingSocketConnections) Sets the maximum number of pending socket connections per HTTP listener.default TwithMaxRequestBodySize(Map<String, Integer> maxRequestBodySize) Sets the maximum size of the HTTP request body by Content-Type.default TwithMaxRequestHeaderSize(int maxRequestHeaderSize) Sets the maximum size of the HTTP request header.default TwithMaxRequestsPerConnection(int maxRequestsPerConnection) Sets the base directory for this server.default TwithMaxResponseChunkSize(int size) This configures the maximum size of a chunk in the response when the server is using chunked response encoding.default TwithMinimumReadThroughput(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.default TwithMinimumWriteThroughput(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.default TwithMultipartBufferSize(int multipartBufferSize) Deprecated.default TwithMultipartConfiguration(MultipartConfiguration multipartStreamConfiguration) Sets the multipart processor configuration.default TwithProcessingTimeoutDuration(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.default TThis configures the duration of the initial delay before calculating and enforcing the minimum read throughput.default TwithRequestBufferSize(int requestBufferSize) Sets the size of the buffer that is used to process the HTTP request.default TwithResponseBufferSize(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.default TwithShutdownDuration(Duration duration) Sets the duration the server will wait for running requests to be completed.default TwithUnexpectedExceptionHandler(HTTPUnexpectedExceptionHandler unexpectedExceptionHandler) Sets the unexpected exception handler.default TThis configures the duration of the initial delay before calculating and enforcing the minimum write throughput.
-
Method Details
-
configuration
HTTPServerConfiguration configuration()- Returns:
- The configuration object.
-
withBaseDir
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.
-
withChunkedBufferSize
Sets the buffer size for the chunked input stream. Defaults to 4 Kilobytes.- Parameters:
chunkedBufferSize- the buffer size used to read a request body that was encoded using 'chunked' transfer-encoding.- Returns:
- This.
-
withCompressByDefault
Sets the default compression behavior for the HTTP response. This behavior can be optionally set per response. SeeHTTPResponse.setCompress(boolean). Defaults to true.Set this configuration to
trueif you want to compress the response when the Accept-Encoding header is present. Set this configuration tofalseif you want to require the request handler to useHTTPResponse.setCompress(boolean)in order to compress the response.Regardless of this configuration, you always have the option to use
HTTPResponse.setCompress(boolean)on a per-response basis as an override.When the request does not contain an Accept-Encoding the response will not be compressed regardless of this configuration.
- Parameters:
compressByDefault- true if you want to compress by default, or false to not compress by default.- Returns:
- This.
-
withContextPath
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 theHTTPRequest.getContextPath()method.- Parameters:
contextPath- The context path for the server.- Returns:
- This.
-
withExpectValidator
Sets an ExpectValidator that is used if a client sends the server aExpect: 100-continueheader.Must not be null.
- Parameters:
validator- The validator.- Returns:
- This.
-
withHandler
Sets the handler that will process the requests.Must not be null.
- Parameters:
handler- The handler that processes the requests.- Returns:
- This.
-
withInitialReadTimeout
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
Sets an instrumenter that the server will notify when events and conditions happen.- Parameters:
instrumenter- The instrumenter.- Returns:
- This.
-
withKeepAliveTimeoutDuration
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
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
Sets the logger factory that all the HTTP server classes use to retrieve specific loggers. Defaults to theSystemOutLoggerFactory.- Parameters:
loggerFactory- The factory.- Returns:
- This.
-
withMaxPendingSocketConnections
Sets the maximum number of pending socket connections per HTTP listener.This number represents how many pending socket connections are allowed to queue before they are rejected. Once the connection is accepted by the server socket, a client socket is created and handed to an HTTP Worker. This queue length only needs to be large enough to buffer the incoming requests as fast as we can accept them and hand them to a worker.
Defaults to 200.
- Returns:
- This.
-
withMaxRequestBodySize
Sets the maximum size of the HTTP request body by Content-Type. If this limit is exceeded, the connection will be closed.The default size is identified by the "*" key. This default value will be used if a more specific value has not been configured for the requested Content-Type.
You may also use wildcards to match one to many subtypes. For example, "application/*" will provide a max size for all content types beginning with application/ when an exact match has not been configured.
An example lookup for the Content-Type "application/x-www-form-urlencoded" is:
- application/x-www-form-urlencoded
- application/*
- *
If the provided configuration does not contain the initial default identified by the "*" key, the server default value will be retained. key.
Set any value to -1 to disable this limitation.
Defaults to 128 Megabytes for the default "*" and 10 Megabytes for "application/x-www-form-urlencoded".
- Parameters:
maxRequestBodySize- a map specifying the maximum size in bytes for the HTTP request body by Content-Type- Returns:
- This.
-
withMaxRequestHeaderSize
Sets the maximum size of the HTTP request header. The request header includes the HTTP request line, and all HTTP request headers, essentially everything except the request body. If this maximum limit is exceeded, the connection will be closed. Defaults to 128 Kilobytes.Set this to -1 to disable this limitation.
- Parameters:
maxRequestHeaderSize- the maximum size in bytes for the HTTP request header- Returns:
- This.
-
withMaxRequestsPerConnection
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. Defaults to 100,000.- Parameters:
maxRequestsPerConnection- The maximum number of requests that can be handled by a single persistent connection.- Returns:
- This.
-
withMaxResponseChunkSize
This configures the maximum size of a chunk in the response when the server is using chunked response encoding. Defaults to 16 Kilobytes.- Parameters:
size- The size in bytes.- Returns:
- This.
-
withMaximumBytesToDrain
Sets the maximum number of bytes the server will allow worker threads to drain after calling the request handler. If the request handler does not read all the bytes, and this limit is exceeded the connection will be closed. Defaults to 128 Kilobytes bytes.- Parameters:
maxBytesToDrain- The maximum number of bytes to drain from the InputStream if the request handler did not read all the available bytes.- Returns:
- This.
-
withMinimumReadThroughput
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
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
Deprecated.use the configuration found inMultipartConfigurationinstead.Sets the size of the buffer that is used to process the multipart request body. This defaults to 16 Kilobytes.- Parameters:
multipartBufferSize- The size of the buffer.- Returns:
- This.
-
withMultipartConfiguration
Sets the multipart processor configuration.This configuration is used when parsing a multipart HTTP request that includes files.
- Parameters:
multipartStreamConfiguration- The configuration.- Returns:
- This
-
withProcessingTimeoutDuration
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
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
Sets the size of the buffer that is used to process the HTTP request. This defaults to 16 Kilobytes.- Parameters:
requestBufferSize- The size of the buffer.- Returns:
- This.
-
withResponseBufferSize
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 64 Kilobytes. Negative values disable the response buffer.Set to -1 do disable buffering completely.
- Parameters:
responseBufferSize- The size of the buffer.- Returns:
- This.
-
withShutdownDuration
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.
-
withUnexpectedExceptionHandler
Sets the unexpected exception handler. This handler will be called when an unexpected exception is taken while processing the HTTP request by the HTTP worker.This allows you to customize the status code and logging behavior.
Must not be null.
- Parameters:
unexpectedExceptionHandler- The unexpected exception handler.- Returns:
- This.
-
withWriteThroughputCalculationDelayDuration
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.
-
MultipartConfigurationinstead.