spring-framework / org.springframework.web.filter / ShallowEtagHeaderFilter

ShallowEtagHeaderFilter

open class ShallowEtagHeaderFilter : OncePerRequestFilter

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 (e.g. a org.springframework.web.servlet.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.

Author
Arjen Poutsma

Author
Rossen Stoyanchev

Author
Brian Clozel

Author
Juergen Hoeller

Since
3.0

Constructors

<init>

ShallowEtagHeaderFilter()

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 (e.g. a org.springframework.web.servlet.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.

Functions

disableContentCaching

open static fun disableContentCaching(request: ServletRequest): Unit

This method can be used to disable the content caching response wrapper of the ShallowEtagHeaderFilter. This can be done before the start of HTTP streaming for example where the response will be written to asynchronously and not in the context of a Servlet container thread.

isWriteWeakETag

open fun isWriteWeakETag(): Boolean

Return whether the ETag value written to the response should be weak, as per RFC 7232.

setWriteWeakETag

open fun setWriteWeakETag(writeWeakETag: Boolean): Unit

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.