Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Tomcat seems to send an ETag header with each response by default. I'd like to disable these for reasons outlined here. I know I can strip them out in my Apache configuration, but is there any way to disable them on the Tomcat side?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

No way disable out of the box. But ETags are set by the DefaultServlet via request.setHeader(). So an easy workaround to disable them is to create a filter for DefaultServlet which swallows the tag. For example:

void doFilter(ServletRequest request, ServletRequest reponse) {
  chain.doFilter(request, new HttpServletResponseWrapper(response) {
      public void setHeader(String name, String value) {
          if (!"etag".equalsIgnoreCase(name)) {
              super.setHeader(name, value);
          }
      }
  });
}

And in web.xml:

  <filter>
    <filter-name>noetag</filter-name>
    <filter-class>foo.NoEtagFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>noetag</filter-name>
    <servlet-name>default</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.