类 ShallowEtagHeaderFilter
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.beans.factory.DisposableBean,cn.taketoday.beans.factory.InitializingBean,cn.taketoday.context.EnvironmentAware,cn.taketoday.core.env.EnvironmentCapable,ServletContextAware,Filter
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.
State-changing HTTP methods and other HTTP conditional request headers such as
If-Match and If-Unmodified-Since are outside the scope of this filter.
Please consider using RequestContext.checkNotModified(String, long) instead.
- 从以下版本开始:
- 4.0 2022/4/9 12:10
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private static classReturns the raw OutputStream, instead of the one that does caching, ifisContentCachingDisabled(jakarta.servlet.http.HttpServletRequest). -
字段概要
字段从类继承的字段 cn.taketoday.web.servlet.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX从类继承的字段 cn.taketoday.web.servlet.filter.GenericFilterBean
logger -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static voiddisableContentCaching(RequestContext request) This method can be used to suppress the content caching response wrapper of the ShallowEtagHeaderFilter.static voiddisableContentCaching(ServletRequest request) This method can be used to suppress the content caching response wrapper of the ShallowEtagHeaderFilter.protected voiddoFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) Same contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread.protected StringgenerateETagHeaderValue(InputStream inputStream, boolean isWeak) Generate the ETag header value from the given response body byte array.private static booleanprotected booleanisEligibleForEtag(HttpServletRequest request, HttpServletResponse response, int responseStatusCode, InputStream inputStream) Whether an ETag should be calculated for the given request and response exchange.booleanReturn whether the ETag value written to the response should be weak, as per RFC 7232.voidsetWriteWeakETag(boolean writeWeakETag) Set whether the ETag value written to the response should be weak, as per RFC 7232.protected booleanThe default value isfalseso that the filter may delay the generation of an ETag until the last asynchronously dispatched thread.private voidupdateResponse(HttpServletRequest request, HttpServletResponse response) 从类继承的方法 cn.taketoday.web.servlet.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatch从类继承的方法 cn.taketoday.web.servlet.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
字段详细资料
-
DIRECTIVE_NO_STORE
- 另请参阅:
-
STREAMING_ATTRIBUTE
-
writeWeakETag
private boolean writeWeakETag
-
-
构造器详细资料
-
ShallowEtagHeaderFilter
public ShallowEtagHeaderFilter()
-
-
方法详细资料
-
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 inweb.xml.- 另请参阅:
-
isWriteWeakETag
public boolean isWriteWeakETag()Return whether the ETag value written to the response should be weak, as per RFC 7232. -
shouldNotFilterAsyncDispatch
protected boolean shouldNotFilterAsyncDispatch()The default value isfalseso that the filter may delay the generation of an ETag until the last asynchronously dispatched thread. -
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException 从类复制的说明:OncePerRequestFilterSame contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
- 指定者:
doFilterInternal在类中OncePerRequestFilter- 抛出:
ServletExceptionIOException
-
updateResponse
private void updateResponse(HttpServletRequest request, HttpServletResponse response) throws IOException - 抛出:
IOException
-
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 istrueif all of the following match:- Response is not committed.
- Response status codes is in the
2xxseries. - Request method is a GET.
- Response Cache-Control header does not contain "no-store" (or is not present at all).
- 参数:
request- the HTTP requestresponse- the HTTP responseresponseStatusCode- the HTTP response status codeinputStream- the response body- 返回:
trueif eligible for ETag generation,falseotherwise
-
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 InputStreamisWeak- whether the generated ETag should be weak- 返回:
- the ETag header value
- 抛出:
IOException- 另请参阅:
-
DigestUtils
-
disableContentCaching
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.
-
disableContentCaching
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.
-
isContentCachingDisabled
-