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 (or 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(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain filterChain)
Same contract as for
doFilter , but guaranteed to be
just invoked once per request. |
protected String |
generateETagHeaderValue(byte[] bytes)
Generate the ETag header value from the given response body byte array.
|
protected boolean |
isEligibleForEtag(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
int responseStatusCode,
byte[] responseBody)
Indicates whether the given request and response are eligible for ETag generation.
|
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain) throws javax.servlet.ServletException, IOException
OncePerRequestFilter
doFilter
, but guaranteed to be
just invoked once per request. Provides HttpServletRequest and
HttpServletResponse arguments instead of the default ServletRequest
and ServletResponse ones.doFilterInternal
in class OncePerRequestFilter
javax.servlet.ServletException
IOException
protected boolean isEligibleForEtag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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
Copyright © 2013. All Rights Reserved.