Class CompressionConfig


  • public class CompressionConfig
    extends java.lang.Object
    Configuration for HTTP response compression settings.
    • Constructor Summary

      Constructors 
      Constructor Description
      CompressionConfig()
      Creates a new compression configuration with default settings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getCompressibleMimeType()
      Returns the comma-separated list of MIME types eligible for compression.
      java.lang.String[] getCompressibleMimeTypes()
      Returns the array of MIME types eligible for compression.
      java.lang.String getCompression()
      Return compression level.
      int getCompressionLevel()
      Returns the internal numeric compression level.
      int getCompressionMinSize()
      Returns the minimum response size in bytes required before compression is applied.
      java.lang.String getNoCompressionEncodings()
      Returns the list of content encodings that indicate already-compressed content.
      java.lang.String getNoCompressionUserAgents()
      Obtain the String form of the regular expression that defines the user agents to not use gzip with.
      java.util.regex.Pattern getNoCompressionUserAgentsPattern()
      Returns the compiled regular expression pattern for user agents that should not receive compressed responses.
      void setCompressibleMimeType​(java.lang.String valueS)
      Sets the comma-separated list of MIME types eligible for compression.
      void setCompression​(java.lang.String compression)
      Set compression level.
      void setCompressionMinSize​(int compressionMinSize)
      Set Minimum size to trigger compression.
      void setNoCompressionEncodings​(java.lang.String encodings)
      Set the list of content encodings that indicate already-compressed content.
      void setNoCompressionUserAgents​(java.lang.String noCompressionUserAgents)
      Set no compression user agent pattern.
      boolean useCompression​(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompressionConfig

        public CompressionConfig()
        Creates a new compression configuration with default settings.
    • Method Detail

      • getNoCompressionEncodings

        public java.lang.String getNoCompressionEncodings()
        Returns the list of content encodings that indicate already-compressed content.
        Returns:
        comma-separated list of encoding names
      • setNoCompressionEncodings

        public void setNoCompressionEncodings​(java.lang.String encodings)
        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

        public void setCompression​(java.lang.String compression)
        Set compression level.
        Parameters:
        compression - One of on, force, off or the minimum compression size in bytes which implies on
      • getCompression

        public java.lang.String 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

        public java.lang.String 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

        public java.util.regex.Pattern getNoCompressionUserAgentsPattern()
        Returns the compiled regular expression pattern for user agents that should not receive compressed responses.
        Returns:
        the compiled pattern, or null if not configured
      • setNoCompressionUserAgents

        public void setNoCompressionUserAgents​(java.lang.String noCompressionUserAgents)
        Set no compression user agent pattern. Regular expression as supported by Pattern. e.g.: gorilla|desesplorer|tigrus.
        Parameters:
        noCompressionUserAgents - The regular expression for user agent strings for which compression should not be applied
      • getCompressibleMimeType

        public java.lang.String getCompressibleMimeType()
        Returns the comma-separated list of MIME types eligible for compression.
        Returns:
        comma-separated MIME type string
      • setCompressibleMimeType

        public void setCompressibleMimeType​(java.lang.String valueS)
        Sets the comma-separated list of MIME types eligible for compression.
        Parameters:
        valueS - comma-separated MIME type string
      • getCompressibleMimeTypes

        public java.lang.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

        public boolean useCompression​(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.
        Parameters:
        request - The request that triggered the response
        response - The response to consider compressing
        Returns:
        true if compression was enabled for the given response, otherwise false