tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <funk...@joedog.org>
Subject Re: How do you set cache-control for static (gif, jpg) resources
Date Fri, 30 Jul 2004 13:51:17 GMT
There is no request or response chain. Its 1 chain. You probably can't set 
headers after doChain() because the response was committed. If anything - you 
should see IllegalStateExceptions in the logs.

If your filter is being executed multiple times (via bad mappings or using 
the 2.4 API incorrectly) - then you might see too many headers.

-Tim

Keith Bottner wrote:

> Previously I was calling doChain at the end of my doFilter method.
> 
> Making the change you suggest, calling doChain at the top like 
> 
> public void doFilter(...)
> {
>     // pass the request/response on
>     chain.doFilter(req, res);
> 
> 	HttpServletResponse response = (HttpServletResponse) res;
> 		
> 	// set the provided HTTP response parameters
> 	Enumeration e = fc.getInitParameterNames();
> 	while ( e.hasMoreElements() )
> 	{
> 		String headerName = (String)e.nextElement();
> 		response.addHeader(headerName,
> fc.getInitParameter(headerName));
> 	}
> }	
> 
> DOES NOT INSERT any of my changes into the response stream. If I do it like
> this:
> 
> public void doFilter(...)
> {
> 	HttpServletResponse response = (HttpServletResponse) res;
> 		
> 	// set the provided HTTP response parameters
> 	Enumeration e = fc.getInitParameterNames();
> 	while ( e.hasMoreElements() )
> 	{
> 		String headerName = (String)e.nextElement();
> 		response.addHeader(headerName,
> fc.getInitParameter(headerName));
> 	}
> 
>     // pass the request/response on
>     chain.doFilter(req, res);
> }
> 
> Then I get two additions in the response stream.
> 
> Any more ideas?
> 
> Keith
> -----Original Message-----
> From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com] 
> Sent: Friday, July 30, 2004 8:20 AM
> To: Tomcat Users List
> Subject: RE: How do you set cache-control for static (gif, jpg) resources
> 
> 
> 
> Hi,
> You have to call chain.doFilter from inside your filter or the request
> doesn't get processed.  If you set the header before the call to
> chain.doFilter, than you're doing it during the request chain.  If you set
> the header after the call to chain.doFilter, then you're doing it during the
> response chain.  In your case the latter is what you want, so after the
> chain.doFilter call.
> 
> Yoav Shapira
> Millennium Research Informatics
> 
> 
> 
>>-----Original Message-----
>>From: Keith Bottner [mailto:kbottner@comcast.net]
>>Sent: Friday, July 30, 2004 9:18 AM
>>To: 'Tomcat Users List'
>>Subject: RE: How do you set cache-control for static (gif, jpg)
> 
> resources
> 
>>Ok, I wrote a simple filter. No problem. It works!
>>
>>One question. Is there a standard way to determine if your filter is
> 
> being
> 
>>called during the request chain or during the response chain?
>>
>>If I use
>>
>>response.putHeader(headerName, fc.getInitParameter(headerName));
>>
>>It will add the header once during the request chain and once during
> 
> the
> 
>>response chain, therefore, anything I add is in their twice.
>>
>>If I use
>>
>>response.setHeader(headerName, fc.getInitParameter(headerName));
>>
>>It will overwrite the current setting, but setting the value twice just 
>>seems like bad form. If I could detect which chain is currently being 
>>processed then I could only insert it once.
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message