Class ResponseHeaderFilter

java.lang.Object
ch.tocco.nice2.web.core.impl.servlet.ResponseHeaderFilter
All Implemented Interfaces:
javax.servlet.Filter

@Component public class ResponseHeaderFilter extends Object implements javax.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 Details

  • Method Details

    • setHeaders

      @Autowired @Lazy public void setHeaders(List<HeaderContribution> contributions)
    • doFilter

      public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException
      Specified by:
      doFilter in interface javax.servlet.Filter
      Throws:
      IOException
      javax.servlet.ServletException