Score:0

Apache expression to read from file and compare

zm flag

I'm trying to write an Apache HTTP 2.4 snippet, where some directives are conditionally applied, if the content of a HTTP header matches a list of strings

This works as expected, the messages are logged if the header is 'x' or 'y'

<If "%{req:X-Header} in { 'x','y' }">
   LogMessage "Header: %{req:X-Header}"
   LogMessage "FileContent: %{file:/tmp/strings_to_compare}"
</If>

The file /tmp/strings_to_compare contains "{ 'x','y' }" and the LogMessage directive also shows this

What I actually want to do is something like this

<If "%{req:X-Header} in %{file:/tmp/strings_to_compare}">
   LogMessage "Header: %{req:X-Header}"
   LogMessage "FileContent: %{file:/tmp/strings_to_compare}"
</If>

But this approach doesn't work, the error message is

AH00526: Syntax error on line ...:
Cannot parse condition clause: syntax error, unexpected T_VAR_BEGIN, expecting T_ID or '{'

Ok, so the expression expects a verbatim list there, and not a function which returns a string. Is there any way to achieve what I'm trying to do?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.