You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jose María Zaragoza <de...@gmail.com> on 2012/11/16 21:38:00 UTC

Modify Cache-Control header

Hi:

I'm using Tomcat 6  ( I don't remember the exact release, I hope to be
forgiven by Pid )

I need to modify Cache-Control header in some responses ( forcing them
to not be cached )
What is the best way to do it ?

a) To implement a Valve ( check request context path and if it match
,to modify response header )
b) To implement a filter
c) Others  ( any property in Tomcat's configuration files that I don't know )

Thanks and regards

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


Re: Modify Cache-Control header

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/11/18 Terence M. Bandoian <te...@tmbsw.com>:
> On 11/16/2012 2:38 PM, Jose María Zaragoza wrote:
>>
>> Hi:
>>
>> I'm using Tomcat 6  ( I don't remember the exact release, I hope to be
>> forgiven by Pid )
>>
>> I need to modify Cache-Control header in some responses ( forcing them
>> to not be cached )
>> What is the best way to do it ?
>>
>> a) To implement a Valve ( check request context path and if it match
>> ,to modify response header )
>> b) To implement a filter
>> c) Others  ( any property in Tomcat's configuration files that I don't
>> know )
>>
>> Thanks and regards
>>
>
> Hi, Jose-
>
> If you have access to the JSP or Java, you might use something like this:
>
>     response.setHeader( "Expires", "-1" );
>     response.setHeader( "Cache-Control", "no-cache" );
>
> See
> http://docs.oracle.com/javaee/6/api/index.html?javax/servlet/http/HttpServletResponse.html
>

+1.

UrlRewriteFilter can be used to set headers, if you do not want to
write the code by yourself.
http://wiki.apache.org/tomcat/AddOns

ExpiresFilter is available in Tomcat 7

Best regards,
Konstantin Kolinko

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


Re: Modify Cache-Control header

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 11/16/2012 2:38 PM, Jose María Zaragoza wrote:
> Hi:
>
> I'm using Tomcat 6  ( I don't remember the exact release, I hope to be
> forgiven by Pid )
>
> I need to modify Cache-Control header in some responses ( forcing them
> to not be cached )
> What is the best way to do it ?
>
> a) To implement a Valve ( check request context path and if it match
> ,to modify response header )
> b) To implement a filter
> c) Others  ( any property in Tomcat's configuration files that I don't know )
>
> Thanks and regards
>

Hi, Jose-

If you have access to the JSP or Java, you might use something like this:

     response.setHeader( "Expires", "-1" );
     response.setHeader( "Cache-Control", "no-cache" );

See 
http://docs.oracle.com/javaee/6/api/index.html?javax/servlet/http/HttpServletResponse.html

-Terence Bandoian


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


Re: Modify Cache-Control header

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jose,

On 11/16/12 3:38 PM, Jose María Zaragoza wrote:
> I need to modify Cache-Control header in some responses ( forcing
> them to not be cached ) What is the best way to do it ?
> 
> a) To implement a Valve ( check request context path and if it
> match ,to modify response header ) b) To implement a filter c)
> Others  ( any property in Tomcat's configuration files that I don't
> know )

I would avoid writing a Valve unless you must: a Valve will tie you to
Tomcat and possibly to a particular version of Tomcat in some cases.

I don't believe Tomcat will mutate your Cache-Control headers so you
are probably safe using a Filter.

I can't really imagine another way to do this besides writing a Filter
or Valve (without using a reverse-proxy as Igor suggests).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlCoShMACgkQ9CaO5/Lv0PDQlwCgxGbXPVOU65ug+BlGtkHdrUkm
UjMAn2wb+lcntQBcp0O4LL3sOWRLxPm8
=Ib7m
-----END PGP SIGNATURE-----

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


Re: Modify Cache-Control header

Posted by Igor Cicimov <ic...@gmail.com>.
On 17/11/2012 7:38 AM, "Jose María Zaragoza" <de...@gmail.com> wrote:
>
> Hi:
>
> I'm using Tomcat 6  ( I don't remember the exact release, I hope to be
> forgiven by Pid )
>
> I need to modify Cache-Control header in some responses ( forcing them
> to not be cached )
> What is the best way to do it ?
>
> a) To implement a Valve ( check request context path and if it match
> ,to modify response header )
> b) To implement a filter
> c) Others  ( any property in Tomcat's configuration files that I don't
know

Or put apache infront and use mod_expiers

>
> Thanks and regards
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>