logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache 2.4 Problem with If-Directive
Author
Chris KL



Joined: 16 Mar 2012
Posts: 3
Location: Malaysia, Kuala Lumpur

PostPosted: Mon 19 Mar '12 6:35    Post subject: Apache 2.4 Problem with If-Directive Reply with quote

Dear All,

I am running Apache 2.4.1 on Windows 7 x64 with PHP 5.3.10. I upgraded mainly because I wanted to make use of the new If-Directive, the upgrading process went very smooth, but now I have a problem exactly with this directive:

Some of my webpages need to modify the response headers generated by Apache, and in order to do so I use PHP to set environment variables. While this works okay with mod_headers only, e.g. "Header unset Expires env=REMOVE_CACHE_HEADERS", the If-Directive would give me more control over the order of processing (because it is processed very late) and make the configuration more structured. However, when I tried it didn't work as expected, and I ended up with the following code for debugging:
Code:
SetEnv REMOVE_CACHE_HEADERS FALSE
<If "env('REMOVE_CACHE_HEADERS') !~ /TRUE/">
   Header set My-header %{REMOVE_CACHE_HEADERS}e
</If>

When I request for webpages which set REMOVE_CACHE_HEADERS to TRUE, my response header will contain the line "My-header: TRUE", in all other cases the response header contains the line "My-header: FALSE", which means the above syntax does not evaluate as desired, e.g. if I change the regex to =~, no header is added at all. However, I am also using the following code:
Code:
<If "req('DNT') =~ /^1.*/">
   Header merge Tk 1
</If>

which works as desired, i.e. the response header only contains the line "Tk: 1" if the request header contained a DNT value of the form "1.*"

Obviously there is a problem with the syntax for evaluating the environment variable, but right now I have no clue what I am missing here, so I hope you will be able to tell me what I am doing wrong, thanks in advance!
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 19 Mar '12 9:17    Post subject: Reply with quote

The docs are grey on this one, I am not satisfied with them. I also think this should be no different then in say LogFormat, so try;

reqenv('REMOVE_CACHE_HEADERS') or
%{REMOVE_CACHE_HEADERS} or
%{REMOVE_CACHE_HEADERS}e <- would be used in LogFormat
Back to top
Chris KL



Joined: 16 Mar 2012
Posts: 3
Location: Malaysia, Kuala Lumpur

PostPosted: Mon 19 Mar '12 10:05    Post subject: Reply with quote

Hi glsmith,

Thanks for your quick reply. Yep, the documentation is not really helpful, I checked 20 over pages, to no avail, funny enough some of the code samples from the original documentation (version 2.4!) caused Apache to refuse to start. With regards to your proposals, I tried all of these before I posted here, with the following outcome:

reqenv('REMOVE_CACHE_HEADERS'):
Same as env('REMOVE_CACHE_HEADERS')

%{REMOVE_CACHE_HEADERS}:
Apache won't even start, error message: Cannot parse condition clause: Variable 'REMOVE_CACHE_HEADERS' does not exist

%{REMOVE_CACHE_HEADERS}e:
Apache won't start again, this time not even an entry in the error log (LogLevel warn)

%{ENV:REMOVE_CACHE_HEADERS}:
Apache will start, but with the same outcome when using the "env" or "reqenv" syntax

So I am pretty lost here, I thought starting with Apache 2.4 the API should be streamlined, but this is obviously not the case. Anyway, not giving up hope yet, hopefully there is somebody around who figured out what is the right syntax for this directive.

Thanks again for the quick reply, anyway!
Back to top
Chris KL



Joined: 16 Mar 2012
Posts: 3
Location: Malaysia, Kuala Lumpur

PostPosted: Tue 20 Mar '12 9:27    Post subject: Reply with quote

After some additional testing I figured out that the problem is obviously not caused by wrong evaluation of the expression, but rather by the internal processing order, looks like the If-directive and the enclosed directives are evaluated at different times, depending on where they actually hook into the process. This lead me to the wrong assumption that something is wrong with the evaluation process, but in fact it only depends on the hooks of the directives used and the time when php sets or modifies the environment variables. In this case the If-directive wouldn't be as useful as I thought, anyway if I have the time I will do some additional tests and post the results here in case they are useful.
Back to top


Reply to topic   Topic: Apache 2.4 Problem with If-Directive View previous topic :: View next topic
Post new topic   Forum Index -> Apache