Class EtagUtils

java.lang.Object
org.eclipse.jetty.http.EtagUtils

public final class EtagUtils extends Object
Utility classes for Entity Tag behaviors as outlined in RFC9110 : Section 8.8.3 - Entity Tag
  • Field Details

    • ETAG_SEPARATOR

      public static final String ETAG_SEPARATOR

      The separator within an etag used to indicate a compressed variant.

      Default separator is --

      Adding a suffix of gzip to an etag of W/"28c772d6" will result in W/"28c772d6--gzip"

      The separator may be changed by the org.eclipse.jetty.http.EtagUtil.ETAG_SEPARATOR System property. If changed, it should be changed to a string that will not be found in a normal etag or at least is very unlikely to be a substring of a normal etag.

  • Method Details

    • createWeakEtagField

      public static HttpField createWeakEtagField(Resource resource)
      Create a new HttpField HttpHeader.ETAG field suitable to represent the provided Resource.
      Parameters:
      resource - the resource to represent with an Etag.
      Returns:
      the field if possible to create etag, or null if not possible.
    • createWeakEtagField

      public static HttpField createWeakEtagField(Resource resource, String etagSuffix)
      Create a new HttpField HttpHeader.ETAG field suitable to represent the provided Resource.
      Parameters:
      resource - the resource to represent with an Etag.
      etagSuffix - the suffix for the etag
      Returns:
      the field if possible to create etag, or null if not possible.
    • computeWeakEtag

      public static String computeWeakEtag(Resource resource)
      Compute the weak etag for the provided Resource reference.

      Will use the Resource.getPath() if the resource provides it, otherwise it will use the Resource provided details from Resource.getName(), Resource.lastModified(), and Resource.length() to build the ETag.

      Parameters:
      resource - the resource to calculate etag from
      Returns:
      the weak etag
    • computeWeakEtag

      public static String computeWeakEtag(Resource resource, String etagSuffix)
      Compute the weak etag for the provided Resource reference.

      Will use the Resource.getPath() if the resource provides it, otherwise it will use the Resource provided details from Resource.getName(), Resource.lastModified(), and Resource.length() to build the ETag.

      Parameters:
      resource - the resource to calculate etag from
      etagSuffix - the suffix for the etag
      Returns:
      the weak etag
    • computeWeakEtag

      public static String computeWeakEtag(Path path)
      Compute the weak etag for the provided Path reference.

      This supports relative path references as well. Which can be useful to establish a reliable etag if the base changes.

      Parameters:
      path - the path to calculate from
      Returns:
      the weak etag
    • computeWeakEtag

      public static String computeWeakEtag(Path path, String suffix)
      Compute the weak etag for the provided Path reference.
      Parameters:
      path - the path to calculate from
      suffix - the optional suffix for the ETag
      Returns:
      the weak etag
    • rewriteWithSuffix

      public static String rewriteWithSuffix(String etag, String newSuffix)
      Rewrite etag with a new suffix, satisfying quoting rules, and preserving optional weak flag.
      Parameters:
      etag - the original etag
      newSuffix - the new suffix to add or change (if a preexisting suffix exists)
      Returns:
      the new etag,
    • isWeak

      public static boolean isWeak(String etag)
      Test if the given Etag is considered weak.
      Parameters:
      etag - the etag to test
      Returns:
      true if weak.
    • isStrong

      public static boolean isStrong(String etag)
      Test if the given Etag is considered strong (not weak).
      Parameters:
      etag - the etag to test
      Returns:
      true if strong (not weak).
    • matches

      public static boolean matches(String etag, String etagWithOptionalSuffix)

      Test if etag matches against an etagWithOptionalSuffix.

      Parameters:
      etag - An etag without a compression suffix
      etagWithOptionalSuffix - An etag optionally with a compression suffix.
      Returns:
      True if the tags are equal.
      See Also: