HTTP Headers Filter

A Java Servlet Filter that sets HTTP headers.
Implementation of javax.servlet.Filter used to set HTTP headers. The filter parameters are treated as HTTP headers. The parameter name becomes the header name, while the parameter value becomes the header value. The parameter value may contain EL expressions. If the expression evaluates to a java.util.Date or a java.lang.Long object the header is considered to be a Date header and formatted according to the HTTP spec.

These are the implicit objects available to the EL context:

now
A java.util.Date object the represents the current time.

Init-params:

negativeMapping
A regular expression matching request URIs to be ignored. The URI is obtained using HttpServletRequest.getRequestURI(). See also the regular expression documentation

This is a typical usage example:

<filter>
  <filter-name>httpHeaders</filter-name>
  <filter-class>
    org.ft.servlet.filters.httpheaders.HTTPHeadersFilter
  </filter-class>
  <init-param>
    <param-name>Expires</param-name>
    <param-value>${now.time + 1000 * 60}</param-value>
  </init-param>
  <init-param>
    <param-name>Last-Modified</param-name>
    <param-value>${now}</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>httpHeaders</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Requirements

Download

Legal

This is Open Source software distributed under the Apache License Version 2.0.

  1. calavera says:

    Thanks for sharing, it’s very useful. This saved me a lot of time.

  2. VKL says:

    Thank you

  3. Michal says:

    Thank you. You`re life saver!

  4. Rolf says:

    This teaches me to search before building it myself ;-) Brilliant, thanks!

  5. stork says:

    What a pity, the link is not working.