Class ResponseHeaderFilter
java.lang.Object
ch.tocco.nice2.web.core.impl.servlet.ResponseHeaderFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
Adds headers to the response.
The headers can be contributed.
Example:
@Bean
public HeaderContribution testCacheControlHeader() {
HeaderContribution contribution = new HeaderContribution();
contribution.setUrlPattern("/([a-f0-9]{7})/([0-9]+)/([^/]+)");
contribution.setName("Cache-Control");
contribution.setValue("no-cache");
contribution.setApplyIfMethod("get,head");
return contribution;
}
In this example, the header "Cache-Control" is set to "max-age=86400" if
the request URL doesn't start with /nice2/dwr.
All attributes:
* name (required)
* value
* headerValueSupplier
If set, value attribute is ignored.
Implementation of HeaderValueSupplier gets called to determine the header value dynamically.
* multiple-values-allowed (default: false):
If the header already is set on the response and multiple-values-allowed
is set to false, the existing value will be overridden.
If multiple-values-allowed is set to true, the new value will be added
without overriding the existing header.
* url-pattern:
The header is only applied, if the request URL matches the pattern
* apply-if-method:
The header is only applied, if the request method is equal to
this value. Multiple methods can be defined separated by comma.
* omit-if-response-header-present (default: false):
If the header is already present on the response, it won't be set, if this flag
is set to true.
* apply-if-request-cookie-present:
Only if one of the given cookies (separated by comma)
is set on the request, the header will be set.
* omit-if-request-cookie-present:
If one of the given cookies (separated by comma) is present,
the header won't be set.
* apply-if-request-header-present:
Only if one of the given headers (separated by comma)
is set on the request, the header will be set.
* omit-if-request-header-present:
If one of the given headers (separated by comma) is present,
the header won't be set.
* apply-if-run-env:
If one of the given run environments (separated by comma) is currently set,
the header will be set. See RunEnv
for a list of all available run
environments.
-
Constructor Summary
ConstructorDescriptionResponseHeaderFilter
(OverrideContributionService overrideContributionService, RunEnvironmentService runEnvironmentService) -
Method Summary
Modifier and TypeMethodDescriptionvoid
doFilter
(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain filterChain) void
setHeaders
(List<HeaderContribution> contributions) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.servlet.Filter
destroy, init
-
Constructor Details
-
ResponseHeaderFilter
@Lazy public ResponseHeaderFilter(OverrideContributionService overrideContributionService, RunEnvironmentService runEnvironmentService)
-
-
Method Details
-
setHeaders
-
doFilter
public void doFilter(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain filterChain) throws IOException, jakarta.servlet.ServletException - Specified by:
doFilter
in interfacejakarta.servlet.Filter
- Throws:
IOException
jakarta.servlet.ServletException
-