You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Brendan Miller <ca...@catphive.net> on 2014/02/01 03:06:59 UTC

how to change headers based on response code in filter

Currently, I have a filter that sets some cache control headers. I need to
change these cache control headers in the case of a non-successful
response, such as a 404.

Unfortunately, when I check HttpServletReponse.getStatus() in the in my
doFilter method, it always reports 200 even if actually a 404 will be sent
to the browser. I'm guessing that the response status isn't yet set at the
point filters are run.

How can I make sending this particular header conditional upon the response
code, so that I only send it in the case of a successful response?

Brendan