You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anurag Kapur <an...@gmail.com> on 2010/03/15 14:12:10 UTC

Conditionally Setting HTTP Response Header

Hello,

Apologies for sending a HTTPD query to the Tomcat list. I am urgently
looking for a response and thought many of you would have ample experience
to answer this.

Thanks
Anurag

---------- Forwarded message ----------
From: Anurag Kapur <an...@gmail.com>
Date: Mon, Mar 15, 2010 at 12:50 PM
Subject: Conditionally Setting HTTP Response Header
To: users@httpd.apache.org
Cc: "Kapur, Anurag" <an...@newsint.co.uk>


Hello,

I am looking for some help to set HTTP response headers conditionally. I
have a setup where HTTPD sits in front of Tomcat and proxies requests to it.

*Problem Statement*
Set a Cache-Control max-age directive in the HTTP response header through
HTTPD if it doesn't already exist. In addition if HTTPD after detecting that
the directive is not already set in the response header, it should set one
depending on the response mime-type.

Example:
HTTPD proxies a request to tomcat -> Tomcat processes the request and send
back the response to HTTPD -> HTTPD checks if Cache-Control max-age
directive is set in the response header. If present it does no changes to
the response header and simply forwards the response back to the user.
However, if the Cache-Control max-age directive is not present it sets one
depending on the response mime type (say max-age=900 for text/html and
max-age=1800 for image/gif)
*
*
*System Info*
$ apachectl -version
Server version: Apache/2.2.9 (Unix)
Server built:   Sep 12 2008 16:23:39

$ uname -a
SunOS vm-sol10-45 5.10 Generic_127128-11 i86pc i386 i86p

*What I Have Tried*
I have been trying to work with mod_setenvif module to start but have not
made any progress and thus seeking your help.

Any inputs would be highly appreciated.

Regards
Anurag
*
*------------------------------------------------------------------
Anurag Kapur
Associate - Technology,
Sapient Corporation.

http://www.linkedin.com/in/anuragkapur

http://www.google.com/profiles/anuragkapur
------------------------------------------------------------------

Re: Conditionally Setting HTTP Response Header

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

Anurag,

On 3/15/2010 12:17 PM, Anurag Kapur wrote:
> Thanks for your reply. I am actually trying to use a combination
> of mod_setenvif and mod_headers. mod_headers can do the job as long as an
> appropriate environment variable is set. I am trying to achieve the desired
> outcome using something like the following:
> 
>   SetEnvIf Cache-Control .+ cc_set=123

This will check for a request header called "Cache-Control".
Cache-Control is likely to be in the /response/ header, so SetEnvIf
can't check for it.

>   Header set Cache-Control "max-age=1000" env=!cc_set
> 
> However, since SetEnvIf directive operates on request (not response)
> headers, I am unable to set the right environment variable to be used by the
> Header directive (a part of mod_headers).

Correct.

> In summary, to be able to use mod_headers to solve this problem, I need an
> environment variable set conditionally based on the "response" header.
> However, I have not been able to achieve this using SetEnvIf, as it operated
> on request headers and not response headers.
> 
> Would be great if someone who knows of an alternate can his/her inputs.

I'm not sure if there's a way to do this with existing httpd components:
you may have to build your own.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEUEARECAAYFAkueYTIACgkQ9CaO5/Lv0PBe3wCSAw1U7FlnYy7sK0N56Ugp1FQs
4QCgv7VZBQMy6FpYlpy3BMSNo3Hwe/M=
=T57K
-----END PGP SIGNATURE-----

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


Re: Conditionally Setting HTTP Response Header

Posted by Anurag Kapur <an...@gmail.com>.
Hi Chris,

Thanks for your reply. I am actually trying to use a combination
of mod_setenvif and mod_headers. mod_headers can do the job as long as an
appropriate environment variable is set. I am trying to achieve the desired
outcome using something like the following:

  SetEnvIf Cache-Control .+ cc_set=123
  Header set Cache-Control "max-age=1000" env=!cc_set

However, since SetEnvIf directive operates on request (not response)
headers, I am unable to set the right environment variable to be used by the
Header directive (a part of mod_headers).

In summary, to be able to use mod_headers to solve this problem, I need an
environment variable set conditionally based on the "response" header.
However, I have not been able to achieve this using SetEnvIf, as it operated
on request headers and not response headers.

Would be great if someone who knows of an alternate can his/her inputs.

Regards
Anurag


On Mon, Mar 15, 2010 at 4:05 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Anurag,
>
> On 3/15/2010 9:12 AM, Anurag Kapur wrote:
> > I am looking for some help to set HTTP response headers conditionally. I
> > have a setup where HTTPD sits in front of Tomcat and proxies requests to
> it.
>
> [snip]
>
> > I have been trying to work with mod_setenvif module to start but have not
> > made any progress and thus seeking your help.
>
> Try looking at mod_headers.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkueWtAACgkQ9CaO5/Lv0PCLHgCfQXl6Jdpg1HCw6PiTElP+qB2l
> 6OoAn1oBY9uCejofCnUP8ko9Ypledp/1
> =nSoB
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Conditionally Setting HTTP Response Header

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

Anurag,

On 3/15/2010 9:12 AM, Anurag Kapur wrote:
> I am looking for some help to set HTTP response headers conditionally. I
> have a setup where HTTPD sits in front of Tomcat and proxies requests to it.

[snip]

> I have been trying to work with mod_setenvif module to start but have not
> made any progress and thus seeking your help.

Try looking at mod_headers.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkueWtAACgkQ9CaO5/Lv0PCLHgCfQXl6Jdpg1HCw6PiTElP+qB2l
6OoAn1oBY9uCejofCnUP8ko9Ypledp/1
=nSoB
-----END PGP SIGNATURE-----

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