Class ETagUtil


  • public final class ETagUtil
    extends Object
    Utility for working with the ETag HTTP caching mechanism.
    Since:
    7.0.5
    Author:
    XIMA MEDIA GmbH
    • 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 return true when it matches the resource.
        Returns:
        true when the condition set by If-Match and If-None-Match headers in the request is fulfilled. Otherwise, returns false. 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 whether the ETag condition is satisfied. If the condition is not satisfied, responds with a 304 Not Modified status code and returns true. In this case, you should abort the remainder of the request processing. If this returns false, 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 return true when it matches the resource.
        Returns:
        true the 304 Not Modified header was sent, false otherwise.
      • setETag

        public static void setETag​(javax.servlet.http.HttpServletResponse response,
                                   ETagUtil.ETag tag)
        Sets the ETag 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 whether the ETag condition is satisfied. If the condition is not satisfied, responds with a 304 Not Modified status code and returns true. In this case, you should abort the remainder of the request processing. Otherwise, sets the given ETag on the response. If this returns false, 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 the 304 Not Modified header.
        Returns:
        true the 304 Not Modified header was sent, false otherwise.