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.
ALREADY_FILTERED_SUFFIX
logger
Constructor and Description |
---|
ShallowEtagHeaderFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain)
Same contract as for
doFilter , but guaranteed to be
just invoked once per request within a single request thread. |
protected String |
generateETagHeaderValue(byte[] bytes)
Generate the ETag header value from the given response body byte array.
|
protected boolean |
isEligibleForEtag(HttpServletRequest request,
HttpServletResponse response,
int responseStatusCode,
byte[] responseBody)
Indicates whether the given request and response are eligible for ETag generation.
|
protected boolean |
shouldNotFilterAsyncDispatch()
The default value is "false" so that the filter may delay the generation of
an ETag until the last asynchronously dispatched thread.
|
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatch
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
protected boolean shouldNotFilterAsyncDispatch()
shouldNotFilterAsyncDispatch
in class OncePerRequestFilter
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
OncePerRequestFilter
doFilter
, but guaranteed to be
just invoked once per request within a single request thread.
See OncePerRequestFilter.shouldNotFilterAsyncDispatch()
for details.
Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
doFilterInternal
in class OncePerRequestFilter
ServletException
IOException
protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response, int responseStatusCode, byte[] responseBody)
The default implementation returns true
for response status codes in the 2xx
series.
request
- the HTTP requestresponse
- the HTTP responseresponseStatusCode
- the HTTP response status coderesponseBody
- the response bodytrue
if eligible for ETag generation; false
otherwiseprotected String generateETagHeaderValue(byte[] bytes)
The default implementation generates an MD5 hash.
bytes
- the response body as byte arrayDigestUtils