Package io.fusionauth.http.server
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintlongThis 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.longThis 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.intintintbooleanwithBaseDir(Path baseDir) Sets the base directory for this server.withCompressByDefault(boolean compressByDefault) Sets the default compression behavior for the HTTP response.withContextPath(String contextPath) Sets the prefix of the URIs that this server handles.withExpectValidator(ExpectValidator validator) Sets an ExpectValidator that is used if a client sends the server aExpect: 100-continueheader.withHandler(HTTPHandler handler) Sets the handler that will process the requests.withInitialReadTimeout(Duration duration) Sets the duration that the server will attempt to read the first byte from a client.withInstrumenter(Instrumenter instrumenter) Sets an instrumenter that the server will notify when events and conditions happen.withKeepAliveTimeoutDuration(Duration duration) Sets the duration that the server will allow client connections to remain open and idle after each request has been processed.withListener(HTTPListenerConfiguration listener) Adds a listener configuration for the server.withLoggerFactory(LoggerFactory loggerFactory) Sets the logger factory that all the HTTP server classes use to retrieve specific loggers.withMaxResponseChunkSize(int size) This configures the maximum size of a chunk in the response when the server is using chunked response encoding.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.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.withMultipartBufferSize(int multipartBufferSize) Sets the size of the buffer that is used to process the multipart request body.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.This configures the duration of the initial delay before calculating and enforcing the minimum read throughput.withRequestBufferSize(int requestBufferSize) Sets the size of the buffer that is used to process the HTTP request.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.withShutdownDuration(Duration duration) Sets the duration the server will wait for running requests to be completed.This configures the duration of the initial delay before calculating and enforcing the minimum write throughput.
-
Constructor Details
-
HTTPServerConfiguration
public HTTPServerConfiguration()
-
-
Method Details
-
configuration
- Specified by:
configurationin interfaceConfigurable<HTTPServerConfiguration>- Returns:
- This.
-
getBaseDir
- Returns:
- The base dir for the entire server. This can be used to calculate files from as needed.
-
getContextPath
- Returns:
- The context page that the entire server serves requests under or null.
-
getExpectValidator
- Returns:
- The expect validator or null.
-
getHandler
- Returns:
- The HTTP handler for this server. Cannot be null and is required.
-
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
- Returns:
- The instrumenter or null.
-
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
- Returns:
- All configured listeners (if any) or an empty list.
-
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
HTTPRequestclass. Defaults to 16k bytes.
-
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
- 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
- Returns:
- The duration that the server will wait while worker threads complete before forcibly shutting itself down. Defaults to 10 seconds.
-
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
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:
withBaseDirin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
baseDir- The base dir.- 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.- Specified by:
withCompressByDefaultin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withContextPathin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withExpectValidatorin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
validator- The validator.- Returns:
- This.
-
withHandler
Sets the handler that will process the requests.- Specified by:
withHandlerin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withInitialReadTimeoutin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
duration- The duration.- Returns:
- This.
-
withInstrumenter
Sets an instrumenter that the server will notify when events and conditions happen.- Specified by:
withInstrumenterin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withKeepAliveTimeoutDurationin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withListenerin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withLoggerFactoryin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
loggerFactory- The factory.- Returns:
- This.
-
withMaxResponseChunkSize
This configures the maximum size of a chunk in the response when the server is using chunked response encoding. Defaults to 16k.- Specified by:
withMaxResponseChunkSizein interfaceConfigurable<HTTPServerConfiguration>- Parameters:
size- The size in 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.- Specified by:
withMinimumReadThroughputin interfaceConfigurable<HTTPServerConfiguration>- 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.- Specified by:
withMinimumWriteThroughputin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
bytesPerSecond- The bytes per second throughput.- Returns:
- This.
-
withMultipartBufferSize
Sets the size of the buffer that is used to process the multipart request body. This defaults to 16k.- Specified by:
withMultipartBufferSizein interfaceConfigurable<HTTPServerConfiguration>- Parameters:
multipartBufferSize- The size of the buffer.- 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.- Specified by:
withProcessingTimeoutDurationin interfaceConfigurable<HTTPServerConfiguration>- 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.
- Specified by:
withReadThroughputCalculationDelayDurationin interfaceConfigurable<HTTPServerConfiguration>- 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 16k.- Specified by:
withRequestBufferSizein interfaceConfigurable<HTTPServerConfiguration>- 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 64k. Negative values disable the response buffer.- Specified by:
withResponseBufferSizein interfaceConfigurable<HTTPServerConfiguration>- Parameters:
responseBufferSize- The size of the buffer. Set to -1 to disable buffering completely.- Returns:
- This.
-
withShutdownDuration
Sets the duration the server will wait for running requests to be completed. Defaults to 10 seconds.- Specified by:
withShutdownDurationin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
duration- The duration the server will wait for all running request processing threads to complete their work.- 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.
- Specified by:
withWriteThroughputCalculationDelayDurationin interfaceConfigurable<HTTPServerConfiguration>- Parameters:
duration- The duration to delay the enforcement of the minimum write throughput.- Returns:
- This.
-