SetEnvIfExpr with response header

apache-2.4

I want to set a environment variable when a specific response header has a value.

But when I make this it doesn't set the variable.

Header add X-foo "bar"
<If "resp('X-foo') == 'bar'">
    Header add X-test-foobar "foobarnew"
</If>

It doesn't set the header X-test-foobar.

Maybe I don't have correctly understand how does it should work. I'm not really fluent in apache programming… I think that programming is not sequential in apache environment but I don't know how to set an env variable with the content of the response header.

Thanks for any help,

ZS

Best Answer

If may be evaluated too early in Apache's processing to use attributes of the response. The documentation isn't clear and I can't find that elsewhere right now.

But the Header directive is processed late, so it can use the response. You just need to add the expr condition to it:

Header add X-test-foobar "foobarnew" "expr=resp('X-foo') == 'bar'"
Related Topic