tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Bottner" <kbott...@comcast.net>
Subject RE: How do you set cache-control for static (gif, jpg) resources
Date Fri, 30 Jul 2004 13:35:31 GMT

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.
>
>Thanks,
>
>Keith
>
>-----Original Message-----
>From: Keith Bottner [mailto:kbottner@comcast.net]
>Sent: Friday, July 30, 2004 7:53 AM
>To: tomcat-user@jakarta.apache.org
>Subject: How do you set cache-control for static (gif, jpg) resources
>
>
>I am trying to find out how I can set my static content for images, 
>javascript and css to have a different cache-control setting. It
appears
>that Tomcat always returns Cache-Control: no-cache with every response.
I
>want to specify certain static resources such as gif and jpg to have
>Cache-Control: public,max-age=7200.
>
>Does anyone know how to configure Tomcat to do this? I have Googled 
>everywhere with no luck!
>
>Keith
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender.  Thank you.


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


---------------------------------------------------------------------
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