You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Nicholas Sherlock <n....@gmail.com> on 2009/01/10 15:19:18 UTC

[users@httpd] mod_headers: Don't add a header if it is already present

Hey everyone,

I'm developing a PHP-based website which was not supplying the correct 
Cache-Control directives in its responses. Even though most of my pages 
are generated especially for the user who is requesting them, I was not 
setting the "Cache-Control: private" response header. As a quick fix, 
I'm using mod_headers like so:

Header append Cache-Control "private"

However, some new pages I am now developing are cache-aware, and supply 
their own Cache-Control headers which should not include the "private" 
modifier. Is it possible for mod_headers to not create this header if 
the response (from PHP) already includes a Cache-Control header? I could 
not work anything out with the conditional controls that the 
documentation mentions for the 'Header' directive, but perhaps I'm just 
a little dense.

Cheers,
Nicholas Sherlock


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: mod_headers: Don't add a header if it is already present

Posted by Nicholas Sherlock <n....@gmail.com>.
Nicholas Sherlock wrote:
> However, some new pages I am now developing are cache-aware, and supply 
> their own Cache-Control headers which should not include the "private" 
> modifier. Is it possible for mod_headers to not create this header if 
> the response (from PHP) already includes a Cache-Control header? 

I found one solution. In my cache-aware PHP pages I can use this code:

apache_setenv("Cache_Aware","yes");

Then mod_headers can look for the environment variable:

Header append Cache-Control "private" env=!Cache_Aware

However, this is suboptimal. Once I eventually fix all of my pages to be 
properly cache-aware, the mod_header directive which adds 'private' will 
no longer be useful, and I'll have a lot of PHP code which needlessly 
sets an Apache environment variable. It'd be great if you could easily 
check for an existing _response_ header in mod_headers!

Cheers,
Nicholas Sherlock


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org