Class EtagUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The separator within an etag used to indicate a compressed variant. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
computeWeakEtag
(Path path) Compute the weak etag for the providedPath
reference.static String
computeWeakEtag
(Path path, String suffix) Compute the weak etag for the providedPath
reference.static String
computeWeakEtag
(Resource resource) Compute the weak etag for the providedResource
reference.static String
computeWeakEtag
(Resource resource, String etagSuffix) Compute the weak etag for the providedResource
reference.static HttpField
createWeakEtagField
(Resource resource) Create a newHttpField
HttpHeader.ETAG
field suitable to represent the provided Resource.static HttpField
createWeakEtagField
(Resource resource, String etagSuffix) Create a newHttpField
HttpHeader.ETAG
field suitable to represent the provided Resource.static boolean
Test if the given Etag is considered strong (not weak).static boolean
Test if the given Etag is considered weak.static boolean
Test if etag matches against an etagWithOptionalSuffix.static String
rewriteWithSuffix
(String etag, String newSuffix) Rewrite etag with a new suffix, satisfying quoting rules, and preserving optional weak flag.
-
Field Details
-
ETAG_SEPARATOR
The separator within an etag used to indicate a compressed variant.
Default separator is
--
Adding a suffix of
gzip
to an etag ofW/"28c772d6"
will result inW/"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
Create a newHttpField
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
Create a newHttpField
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
Compute the weak etag for the providedResource
reference.Will use the
Resource.getPath()
if the resource provides it, otherwise it will use theResource
provided details fromResource.getName()
,Resource.lastModified()
, andResource.length()
to build the ETag.- Parameters:
resource
- the resource to calculate etag from- Returns:
- the weak etag
-
computeWeakEtag
Compute the weak etag for the providedResource
reference.Will use the
Resource.getPath()
if the resource provides it, otherwise it will use theResource
provided details fromResource.getName()
,Resource.lastModified()
, andResource.length()
to build the ETag.- Parameters:
resource
- the resource to calculate etag frometagSuffix
- the suffix for the etag- Returns:
- the weak etag
-
computeWeakEtag
Compute the weak etag for the providedPath
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
Compute the weak etag for the providedPath
reference.- Parameters:
path
- the path to calculate fromsuffix
- the optional suffix for the ETag- Returns:
- the weak etag
-
rewriteWithSuffix
Rewrite etag with a new suffix, satisfying quoting rules, and preserving optional weak flag.- Parameters:
etag
- the original etagnewSuffix
- the new suffix to add or change (if a preexisting suffix exists)- Returns:
- the new etag,
-
isWeak
Test if the given Etag is considered weak.- Parameters:
etag
- the etag to test- Returns:
- true if weak.
-
isStrong
Test if the given Etag is considered strong (not weak).- Parameters:
etag
- the etag to test- Returns:
- true if strong (not weak).
-
matches
Test if etag matches against an etagWithOptionalSuffix.
- Parameters:
etag
- An etag without a compression suffixetagWithOptionalSuffix
- An etag optionally with a compression suffix.- Returns:
- True if the tags are equal.
- See Also:
-