I have a filter with doFilter method like this:

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
        throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        resp.setHeader("Cache-Control",
                       "must-revalidate, max-age=0, post-check=0,
pre-check=0");

        chain.doFilter(request, response);
    }

This sets the header. However, if I set the header *after* chain.doFilter,
the header is not set. Why is this?

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
        throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        chain.doFilter(request, response);

        resp.setHeader("Cache-Control",
                       "must-revalidate, max-age=0, post-check=0,
pre-check=0");
    }

Programmatically I can see the header is null.

Has the content already been sent to the web browser after chain.doFilter?
If so, is there a way to delay sending data to the browser? I need to
inspect the status code in the response before setting my header (to
prevent 404's from being cached).

Thanks,
Brendan Miller

Reply via email to