public class

ShallowEtagHeaderFilter

extends OncePerRequestFilter
java.lang.Object
   ↳ org.springframework.web.filter.GenericFilterBean
     ↳ org.springframework.web.filter.OncePerRequestFilter
       ↳ org.springframework.web.filter.ShallowEtagHeaderFilter

Class Overview

javax.servlet.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 (or View) is still rendered. As such, this filter only saves bandwidth, not server performance.

Summary

[Expand]
Inherited Constants
From class org.springframework.web.filter.OncePerRequestFilter
[Expand]
Inherited Fields
From class org.springframework.web.filter.GenericFilterBean
Public Constructors
ShallowEtagHeaderFilter()
Protected Methods
void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as for doFilter, but guaranteed to be just invoked once per request.
String generateETagHeaderValue(byte[] bytes)
Generate the ETag header value from the given response body byte array.
boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response, int responseStatusCode, byte[] responseBody)
Indicates whether the given request and response are eligible for ETag generation.
[Expand]
Inherited Methods
From class org.springframework.web.filter.OncePerRequestFilter
From class org.springframework.web.filter.GenericFilterBean
From class java.lang.Object
From interface javax.servlet.Filter
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.context.EnvironmentAware
From interface org.springframework.web.context.ServletContextAware

Public Constructors

public ShallowEtagHeaderFilter ()

Protected Methods

protected void doFilterInternal (HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)

Same contract as for doFilter, but guaranteed to be just invoked once per request. Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.

Throws
IOException
ServletException

protected String generateETagHeaderValue (byte[] bytes)

Generate the ETag header value from the given response body byte array.

The default implementation generates an MD5 hash.

Parameters
bytes the response body as byte array
Returns
  • the ETag header value
See Also

protected boolean isEligibleForEtag (HttpServletRequest request, HttpServletResponse response, int responseStatusCode, byte[] responseBody)

Indicates whether the given request and response are eligible for ETag generation.

The default implementation returns true for response status codes in the 2xx series.

Parameters
request the HTTP request
response the HTTP response
responseStatusCode the HTTP response status code
responseBody the response body
Returns
  • true if eligible for ETag generation; false otherwise