I was trying to whittle down the cases where the Access-Control-Allow-Origin
is sent in a response to only some specific scenarios such as only for specific request methods. In this situation we already included the response header on all requests for a specific directory but then after adding the If
condition below it no longer seems to work.
<Directory "/var/www/myapp">
<If "%{REQUEST_METHOD} == 'HEAD'">
Header set Access-Control-Allow-Origin 'https://some.example.com'
</If>
</Directory>
What's more is that I have also tried to debug this through various means and from what I can tell the %{REQUEST_METHOD}
variable is not being resolved correctly. Here are the tests that I've done to determine this so far.
✔ No condition includes the header as expected.
<Directory "/var/www/myapp">
Header set Access-Control-Allow-Origin 'https://some.example.com'
</Directory>
✔ Condition which should always be true, includes the header as expected.
<Directory "/var/www/myapp">
<If "'HEAD' == 'HEAD'">
Header set Access-Control-Allow-Origin 'https://some.example.com'
</If>
</Directory>
❌ Add a header to echo the value resolved by %{REQUEST_METHOD}
seems to break Apache, response comes back with no headers looks like an error in handling.
<Directory "/var/www/myapp">
Header set X-Method "%{REQUEST_METHOD}"
Header set Access-Control-Allow-Origin 'https://some.example.com'
</Directory>
I can't help to think that I must have some syntax wrong but I've checked things over several times and nothing sticks out to me.