Package de.xima.fc.web.common.utils
Class ETagUtil
- java.lang.Object
-
- de.xima.fc.web.common.utils.ETagUtil
-
public final class ETagUtil extends Object
Utility for working with the ETag HTTP caching mechanism.- Since:
- 7.0.5
- Author:
- XIMA MEDIA GmbH
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ETagUtil.ETag
POJO models for an ETag that can be exchanged via HTTP requests for cache control etc.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<ETagUtil.ETag>
getIfMatch(javax.servlet.http.HttpServletRequest request)
static Set<ETagUtil.ETag>
getIfNoneMatch(javax.servlet.http.HttpServletRequest request)
static Optional<Boolean>
isETagConditionSatisified(javax.servlet.http.HttpServletRequest request, Predicate<ETagUtil.ETag> matcher)
static boolean
respondNotModifiedIfUnchanged(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Predicate<ETagUtil.ETag> matcher)
Checks whetherthe ETag condition is satisfied
.static void
setETag(javax.servlet.http.HttpServletResponse response, ETagUtil.ETag tag)
Sets theETag
header to the given response.static boolean
skipIfNotModified(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ETagUtil.ETag tag)
Checks whetherthe ETag condition is satisfied
.
-
-
-
Method Detail
-
getIfMatch
public static Set<ETagUtil.ETag> getIfMatch(javax.servlet.http.HttpServletRequest request)
- Parameters:
request
- An HTTP servlet request.- Returns:
- All ETags present in the
If-Match
header.
-
getIfNoneMatch
public static Set<ETagUtil.ETag> getIfNoneMatch(javax.servlet.http.HttpServletRequest request)
- Parameters:
request
- An HTTP servlet request.- Returns:
- All ETags present in the
If-None-Match
header.
-
isETagConditionSatisified
public static Optional<Boolean> isETagConditionSatisified(javax.servlet.http.HttpServletRequest request, Predicate<ETagUtil.ETag> matcher)
- Parameters:
request
- An HTTP servlet request.matcher
- A predicate function that is given an ETag and must returntrue
when it matches the resource.- Returns:
true
when the condition set byIf-Match
andIf-None-Match
headers in the request is fulfilled. Otherwise, returnsfalse
. When the request does not contain any such headers, returns an empty optional.
-
respondNotModifiedIfUnchanged
public static boolean respondNotModifiedIfUnchanged(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Predicate<ETagUtil.ETag> matcher)
Checks whetherthe ETag condition is satisfied
. If the condition is not satisfied, responds with a304 Not Modified
status code and returnstrue
. In this case, you should abort the remainder of the request processing. If this returnsfalse
, you should process with the request as normally.- Parameters:
request
- An HTTP servlet request.response
- An HTTP servlet response.matcher
- A predicate function that is given an ETag and must returntrue
when it matches the resource.- Returns:
true
the304 Not Modified
header was sent,false
otherwise.
-
setETag
public static void setETag(javax.servlet.http.HttpServletResponse response, ETagUtil.ETag tag)
Sets theETag
header to the given response.- Parameters:
response
- An HTTP servlet response.tag
- The ETag to set.
-
skipIfNotModified
public static boolean skipIfNotModified(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ETagUtil.ETag tag)
Checks whetherthe ETag condition is satisfied
. If the condition is not satisfied, responds with a304 Not Modified
status code and returnstrue
. In this case, you should abort the remainder of the request processing. Otherwise, sets the given ETag on the response. If this returnsfalse
, you should process with the request as normally.- Parameters:
request
- An HTTP servlet request.response
- An HTTP servlet response.tag
- The ETag that the request should have to send the304 Not Modified
header.- Returns:
true
the304 Not Modified
header was sent,false
otherwise.
-
-