You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Mohammed Salih <li...@gmail.com> on 2008/04/21 14:09:13 UTC
[users@httpd] Adding a Header to the httpd response
Hi All,
How can I add a header, if it is not set by the application.
I want to add Cache-Control header to all http responses, if it is not
set by the back-end application like PHP or application server like
tomcat.
I tried a combination of SetEnvIf and Header, but SetEnvIf is only
fused for requests.
Can any one please guide me in the right path? (Sorrmy English is poor)
Thanks in advance.
Salih
---------------------------------------------------------------------
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
Re: [users@httpd] Adding a Header to the httpd response
Posted by Mohammed Salih <li...@gmail.com>.
Thank you Tamer for the patch.
Unfortunately we can not apply this on to our production server,
because of some company policies. But for sure I will check this out
on our test server.
Regards
Salih
On Wed, Apr 23, 2008 at 4:34 PM, Tamer Embaby <Ta...@itworx.com> wrote:
> Salih,
>
> Here is a patch that could be run against mod_headers.c that will
> add a new action "fset" which will set a header only if the header is
> not set before.
>
> Apply the patch using:
> $ patch mod_headers.c < mod_headers.c.fset_patch
>
> Compile and install to your 2.2.X Apache using:
> $ /path/to/apache/bin/apxs -i -c mod_headers.c
>
> Use it as:
> Header fset MyHeader "Some Text"
>
> I couldn't get a better name than "fset". Also this is built and tested
> against 2.2.8, I don't know if it should be different for 2.0.X.
>
> Regards,
> Tamer
>
>
> -----Original Message-----
> From: Mohammed Salih [mailto:linusali@gmail.com]
>
> Sent: Tuesday, April 22, 2008 9:56 AM
> To: users@httpd.apache.org
>
>
> Subject: Re: [users@httpd] Adding a Header to the httpd response
>
> Thank you Joshua for your response,
>
> I tried to use the SetEnvIf and Header combination before, but as you
> said SetEnvIf is only useful for the request headers.
> So can you please help me in creating the negative-lookahead regex. I
> am very bad at regex.
>
> Thanks in advance.
> Salih
>
> On Mon, Apr 21, 2008 at 6:47 PM, Joshua Slive <jo...@slive.ca> wrote:
> > On Mon, Apr 21, 2008 at 10:34 AM, Joshua Slive <jo...@slive.ca> wrote:
> > > On Mon, Apr 21, 2008 at 9:38 AM, Mohammed Salih <li...@gmail.com> wrote:
> > > > Thank you all for your reply.
> > > >
> > > > Yes I am using Header to set the Cache-Control header. and it is doing
> > > > it job. but some times the application might have already set this
> > > > header. So I want to avoid setting it again using the Header module.
> > > >
> > >
> > > See example #4:
> > > http://httpd.apache.org/docs/2.2/mod/mod_headers.html#examples
> > >
> > > SetEnvIf Cache-Control .+ got-cache-control=1
> > > Header set Cache-Control blah env=!got-cache-control
> >
> > Oh, wait a sec. That's not going to work because SetEnvIf matches
> > request headers, not response headers.
> >
> > You could try "Header edit" using a negative-lookahead regex to
> > exclude requests already containing something in Cache-Control. Other
> > than that, I think this would require a simple custom module.
> >
> >
> >
> > Joshua.
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
>
> ---------------------------------------------------------------------
> 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
>
>
> ---------------------------------------------------------------------
> 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
>
---------------------------------------------------------------------
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
RE: [users@httpd] Adding a Header to the httpd response
Posted by Tamer Embaby <Ta...@itworx.com>.
Salih,
Here is a patch that could be run against mod_headers.c that will
add a new action "fset" which will set a header only if the header is
not set before.
Apply the patch using:
$ patch mod_headers.c < mod_headers.c.fset_patch
Compile and install to your 2.2.X Apache using:
$ /path/to/apache/bin/apxs -i -c mod_headers.c
Use it as:
Header fset MyHeader "Some Text"
I couldn't get a better name than "fset". Also this is built and tested
against 2.2.8, I don't know if it should be different for 2.0.X.
Regards,
Tamer
-----Original Message-----
From: Mohammed Salih [mailto:linusali@gmail.com]
Sent: Tuesday, April 22, 2008 9:56 AM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Adding a Header to the httpd response
Thank you Joshua for your response,
I tried to use the SetEnvIf and Header combination before, but as you
said SetEnvIf is only useful for the request headers.
So can you please help me in creating the negative-lookahead regex. I
am very bad at regex.
Thanks in advance.
Salih
On Mon, Apr 21, 2008 at 6:47 PM, Joshua Slive <jo...@slive.ca> wrote:
> On Mon, Apr 21, 2008 at 10:34 AM, Joshua Slive <jo...@slive.ca> wrote:
> > On Mon, Apr 21, 2008 at 9:38 AM, Mohammed Salih <li...@gmail.com> wrote:
> > > Thank you all for your reply.
> > >
> > > Yes I am using Header to set the Cache-Control header. and it is doing
> > > it job. but some times the application might have already set this
> > > header. So I want to avoid setting it again using the Header module.
> > >
> >
> > See example #4:
> > http://httpd.apache.org/docs/2.2/mod/mod_headers.html#examples
> >
> > SetEnvIf Cache-Control .+ got-cache-control=1
> > Header set Cache-Control blah env=!got-cache-control
>
> Oh, wait a sec. That's not going to work because SetEnvIf matches
> request headers, not response headers.
>
> You could try "Header edit" using a negative-lookahead regex to
> exclude requests already containing something in Cache-Control. Other
> than that, I think this would require a simple custom module.
>
>
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
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
Re: [users@httpd] Adding a Header to the httpd response
Posted by Mohammed Salih <li...@gmail.com>.
Thank you Joshua for your response,
I tried to use the SetEnvIf and Header combination before, but as you
said SetEnvIf is only useful for the request headers.
So can you please help me in creating the negative-lookahead regex. I
am very bad at regex.
Thanks in advance.
Salih
On Mon, Apr 21, 2008 at 6:47 PM, Joshua Slive <jo...@slive.ca> wrote:
> On Mon, Apr 21, 2008 at 10:34 AM, Joshua Slive <jo...@slive.ca> wrote:
> > On Mon, Apr 21, 2008 at 9:38 AM, Mohammed Salih <li...@gmail.com> wrote:
> > > Thank you all for your reply.
> > >
> > > Yes I am using Header to set the Cache-Control header. and it is doing
> > > it job. but some times the application might have already set this
> > > header. So I want to avoid setting it again using the Header module.
> > >
> >
> > See example #4:
> > http://httpd.apache.org/docs/2.2/mod/mod_headers.html#examples
> >
> > SetEnvIf Cache-Control .+ got-cache-control=1
> > Header set Cache-Control blah env=!got-cache-control
>
> Oh, wait a sec. That's not going to work because SetEnvIf matches
> request headers, not response headers.
>
> You could try "Header edit" using a negative-lookahead regex to
> exclude requests already containing something in Cache-Control. Other
> than that, I think this would require a simple custom module.
>
>
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
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
Re: [users@httpd] Adding a Header to the httpd response
Posted by Joshua Slive <jo...@slive.ca>.
On Mon, Apr 21, 2008 at 10:34 AM, Joshua Slive <jo...@slive.ca> wrote:
> On Mon, Apr 21, 2008 at 9:38 AM, Mohammed Salih <li...@gmail.com> wrote:
> > Thank you all for your reply.
> >
> > Yes I am using Header to set the Cache-Control header. and it is doing
> > it job. but some times the application might have already set this
> > header. So I want to avoid setting it again using the Header module.
> >
>
> See example #4:
> http://httpd.apache.org/docs/2.2/mod/mod_headers.html#examples
>
> SetEnvIf Cache-Control .+ got-cache-control=1
> Header set Cache-Control blah env=!got-cache-control
Oh, wait a sec. That's not going to work because SetEnvIf matches
request headers, not response headers.
You could try "Header edit" using a negative-lookahead regex to
exclude requests already containing something in Cache-Control. Other
than that, I think this would require a simple custom module.
Joshua.
---------------------------------------------------------------------
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
Re: [users@httpd] Adding a Header to the httpd response
Posted by Joshua Slive <jo...@slive.ca>.
On Mon, Apr 21, 2008 at 9:38 AM, Mohammed Salih <li...@gmail.com> wrote:
> Thank you all for your reply.
>
> Yes I am using Header to set the Cache-Control header. and it is doing
> it job. but some times the application might have already set this
> header. So I want to avoid setting it again using the Header module.
>
See example #4:
http://httpd.apache.org/docs/2.2/mod/mod_headers.html#examples
SetEnvIf Cache-Control .+ got-cache-control=1
Header set Cache-Control blah env=!got-cache-control
Joshua.
---------------------------------------------------------------------
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
Re: [users@httpd] Adding a Header to the httpd response
Posted by Mohammed Salih <li...@gmail.com>.
Thank you all for your reply.
Yes I am using Header to set the Cache-Control header. and it is doing
it job. but some times the application might have already set this
header. So I want to avoid setting it again using the Header module.
Thanks again in advance.
On Mon, Apr 21, 2008 at 4:18 PM, Jeremy Jones <Je...@s1now.com> wrote:
> Hi,
>
> Something like this in httpd.conf works for me:
>
>
>
> <IfModule mod_headers.c>
> <LocationMatch \.(js|gif|jpe?g|css)>
> Header append "Cache-Control" "public"
> </LocationMatch>
> <LocationMatch \.s?html>
> Header append "Cache-Control" "private"
> </LocationMatch>
> </IfModule>
>
>
> so without the LocationMatch it could handle everything I think.
>
>
> Jeremy
>
>
>
>
>
>
> -----Original Message-----
> From: Mohammed Salih [mailto:linusali@gmail.com]
> Sent: 21 April 2008 13:09
> To: users@httpd.apache.org
> Subject: [users@httpd] Adding a Header to the httpd response
>
> Hi All,
>
> How can I add a header, if it is not set by the application.
>
> I want to add Cache-Control header to all http responses, if it is not
> set by the back-end application like PHP or application server like
> tomcat.
>
> I tried a combination of SetEnvIf and Header, but SetEnvIf is only
> fused for requests.
>
> Can any one please guide me in the right path? (Sorrmy English is poor)
>
> Thanks in advance.
> Salih
>
> ---------------------------------------------------------------------
> 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
>
>
> --------------------------------------------------------------------
> This email has been scanned for viruses and other threats
> using Newsquest's Ironport email filters
>
> This e-mail, including any attachment, is private and
> confidential.
> It should not be read, copied, disclosed or otherwise used by
> any person other than the intended recipient(s).
> If you have received this e-mail in error, please notify the
> sender immediately.
> Newsquest reserves the right to monitor e-mails in
> accordance with the Telecommunications (Lawful Business
> Practice)
> (Interception of Communications) Regulations 2000.
>
> Newsquest Limited.
> Registered in England, number 3105111 . Registered office:
> 58 Church Street, Weybridge, Surrey KT13 8DP
> --------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
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
RE: [users@httpd] Adding a Header to the httpd response
Posted by Jeremy Jones <Je...@s1now.com>.
Hi,
Something like this in httpd.conf works for me:
<IfModule mod_headers.c>
<LocationMatch \.(js|gif|jpe?g|css)>
Header append "Cache-Control" "public"
</LocationMatch>
<LocationMatch \.s?html>
Header append "Cache-Control" "private"
</LocationMatch>
</IfModule>
so without the LocationMatch it could handle everything I think.
Jeremy
-----Original Message-----
From: Mohammed Salih [mailto:linusali@gmail.com]
Sent: 21 April 2008 13:09
To: users@httpd.apache.org
Subject: [users@httpd] Adding a Header to the httpd response
Hi All,
How can I add a header, if it is not set by the application.
I want to add Cache-Control header to all http responses, if it is not
set by the back-end application like PHP or application server like
tomcat.
I tried a combination of SetEnvIf and Header, but SetEnvIf is only
fused for requests.
Can any one please guide me in the right path? (Sorrmy English is poor)
Thanks in advance.
Salih
---------------------------------------------------------------------
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
--------------------------------------------------------------------
This email has been scanned for viruses and other threats
using Newsquest's Ironport email filters
This e-mail, including any attachment, is private and
confidential.
It should not be read, copied, disclosed or otherwise used by
any person other than the intended recipient(s).
If you have received this e-mail in error, please notify the
sender immediately.
Newsquest reserves the right to monitor e-mails in
accordance with the Telecommunications (Lawful Business
Practice)
(Interception of Communications) Regulations 2000.
Newsquest Limited.
Registered in England, number 3105111 . Registered office:
58 Church Street, Weybridge, Surrey KT13 8DP
--------------------------------------------------------------------
---------------------------------------------------------------------
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
AW: [users@httpd] Adding a Header to the httpd response
Posted by ch...@post.ch.
Hey Salih,
You should use mod_headers.
http://httpd.apache.org/docs/2.2/mod/mod_headers.html
Cheers,
Christian
-----Ursprüngliche Nachricht-----
Von: Mohammed Salih [mailto:linusali@gmail.com]
Gesendet: Montag, 21. April 2008 14:09
An: users@httpd.apache.org
Betreff: [users@httpd] Adding a Header to the httpd response
Hi All,
How can I add a header, if it is not set by the application.
I want to add Cache-Control header to all http responses, if it is not set by the back-end application like PHP or application server like tomcat.
I tried a combination of SetEnvIf and Header, but SetEnvIf is only fused for requests.
Can any one please guide me in the right path? (Sorrmy English is poor)
Thanks in advance.
Salih
---------------------------------------------------------------------
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
---------------------------------------------------------------------
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