类 ShallowEtagHeaderFilter

  • 所有已实现的接口:
    Filter, Aware, BeanNameAware, DisposableBean, InitializingBean, EnvironmentAware, EnvironmentCapable, ServletContextAware

    public class ShallowEtagHeaderFilter
    extends OncePerRequestFilter
    Filter that generates an ETag value based on the content on the response. This ETag is compared to the If-None-Match header of the request. If these headers are equal, the response content is not sent, but rather a 304 "Not Modified" status instead.

    Since the ETag is based on the response content, the response (e.g. a View) is still rendered. As such, this filter only saves bandwidth, not server performance.

    NOTE: As of Spring Framework 5.0, this filter uses request/response decorators built on the Servlet 3.1 API.

    从以下版本开始:
    3.0
    作者:
    Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
    • 方法详细资料

      • setWriteWeakETag

        public void setWriteWeakETag​(boolean writeWeakETag)
        Set whether the ETag value written to the response should be weak, as per RFC 7232.

        Should be configured using an <init-param> for parameter name "writeWeakETag" in the filter definition in web.xml.

        从以下版本开始:
        4.3
        另请参阅:
        RFC 7232 section 2.3
      • isWriteWeakETag

        public boolean isWriteWeakETag()
        Return whether the ETag value written to the response should be weak, as per RFC 7232.
        从以下版本开始:
        4.3
      • isEligibleForEtag

        protected boolean isEligibleForEtag​(HttpServletRequest request,
                                            HttpServletResponse response,
                                            int responseStatusCode,
                                            InputStream inputStream)
        Whether an ETag should be calculated for the given request and response exchange. By default this is true if all of the following match:
        • Response is not committed.
        • Response status codes is in the 2xx series.
        • Request method is a GET.
        • Response Cache-Control header does not contain "no-store" (or is not present at all).
        参数:
        request - the HTTP request
        response - the HTTP response
        responseStatusCode - the HTTP response status code
        inputStream - the response body
        返回:
        true if eligible for ETag generation, false otherwise
      • generateETagHeaderValue

        protected String generateETagHeaderValue​(InputStream inputStream,
                                                 boolean isWeak)
                                          throws IOException
        Generate the ETag header value from the given response body byte array.

        The default implementation generates an MD5 hash.

        参数:
        inputStream - the response body as an InputStream
        isWeak - whether the generated ETag should be weak
        返回:
        the ETag header value
        抛出:
        IOException
        另请参阅:
        DigestUtils
      • disableContentCaching

        public static void disableContentCaching​(ServletRequest request)
        This method can be used to suppress the content caching response wrapper of the ShallowEtagHeaderFilter. The main reason for this is streaming scenarios which are not to be cached and do not need an eTag.

        Note: This method must be called before the response is written to in order for the entire response content to be written without caching.

        从以下版本开始:
        4.2