Class CompressionConfig
java.lang.Object
org.apache.coyote.CompressionConfig
Configuration for HTTP response compression settings.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new compression configuration with default settings. -
Method Summary
Modifier and TypeMethodDescriptionReturns the comma-separated list of MIME types eligible for compression.String[]Returns the array of MIME types eligible for compression.Return compression level.intReturns the internal numeric compression level.intReturns the minimum response size in bytes required before compression is applied.Returns the list of content encodings that indicate already-compressed content.Obtain the String form of the regular expression that defines the user agents to not use gzip with.Returns the compiled regular expression pattern for user agents that should not receive compressed responses.voidsetCompressibleMimeType(String valueS) Sets the comma-separated list of MIME types eligible for compression.voidsetCompression(String compression) Set compression level.voidsetCompressionMinSize(int compressionMinSize) Set Minimum size to trigger compression.voidsetNoCompressionEncodings(String encodings) Set the list of content encodings that indicate already-compressed content.voidsetNoCompressionUserAgents(String noCompressionUserAgents) Set no compression user agent pattern.booleanuseCompression(Request request, Response response) Determines if compression should be enabled for the given response and if it is, sets any necessary headers to mark it as such.
-
Constructor Details
-
CompressionConfig
public CompressionConfig()Creates a new compression configuration with default settings.
-
-
Method Details
-
getNoCompressionEncodings
Returns the list of content encodings that indicate already-compressed content.- Returns:
- comma-separated list of encoding names
-
setNoCompressionEncodings
Set the list of content encodings that indicate already-compressed content. When content is already encoded with one of these encodings, compression will not be applied to prevent double compression.- Parameters:
encodings- Comma-separated list of encoding names (e.g., "gzip,br.dflate")
-
setCompression
Set compression level.- Parameters:
compression- One ofon,force,offor the minimum compression size in bytes which implieson
-
getCompression
Return compression level.- Returns:
- The current compression level in string form (off/on/force)
-
getCompressionLevel
public int getCompressionLevel()Returns the internal numeric compression level.- Returns:
- 0 for off, 1 for on, 2 for force
-
getNoCompressionUserAgents
Obtain the String form of the regular expression that defines the user agents to not use gzip with.- Returns:
- The regular expression as a String
-
getNoCompressionUserAgentsPattern
Returns the compiled regular expression pattern for user agents that should not receive compressed responses.- Returns:
- the compiled pattern, or
nullif not configured
-
setNoCompressionUserAgents
Set no compression user agent pattern. Regular expression as supported byPattern. e.g.:gorilla|desesplorer|tigrus.- Parameters:
noCompressionUserAgents- The regular expression for user agent strings for which compression should not be applied
-
getCompressibleMimeType
Returns the comma-separated list of MIME types eligible for compression.- Returns:
- comma-separated MIME type string
-
setCompressibleMimeType
Sets the comma-separated list of MIME types eligible for compression.- Parameters:
valueS- comma-separated MIME type string
-
getCompressibleMimeTypes
Returns the array of MIME types eligible for compression.- Returns:
- array of MIME type strings
-
getCompressionMinSize
public int getCompressionMinSize()Returns the minimum response size in bytes required before compression is applied.- Returns:
- the minimum size in bytes
-
setCompressionMinSize
public void setCompressionMinSize(int compressionMinSize) Set Minimum size to trigger compression.- Parameters:
compressionMinSize- The minimum content length required for compression in bytes
-
useCompression
Determines if compression should be enabled for the given response and if it is, sets any necessary headers to mark it as such.- Parameters:
request- The request that triggered the responseresponse- The response to consider compressing- Returns:
trueif compression was enabled for the given response, otherwisefalse
-