On Thu, 2014-03-13 at 17:51 -0700, Brendan Miller wrote:
> 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?
> 
A similar question came up last week.  Basically, it's because the
response has already been committed.  A response becomes committed once
the 1st byte is sent back to the client -- e.g. if flush() is called or
the buffer becomes full while more response data is written.

You can search the archive for how it was resolved.  Don't recall the
subject line.  Sorry.

-- Tim

>     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



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to