1. Caddy version (caddy version
):
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=
2. How I run Caddy:
a. System environment:
macOS 12.1 on amd64. Running the downloaded binary from GitHub releases.
b. Command:
ENVIRONMENT=production ./caddy run --config ~/Desktop/Caddyfile
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
{
debug
auto_https off
http_port 9080
}
http://* {
@my_multiple_expression_matcher {
expression "{query.foo} == \"bar\""
expression "{env.ENVIRONMENT} == \"production\""
}
respond @my_multiple_expression_matcher 200 {
body "Matched all expressions"
}
respond 200 {
body "Matched some or no expressions"
}
}
3. The problem I’m having:
I have a named matcher (my_multiple_expression_matcher
containing two expression matchers. Both should evaluate to true in order to satisfy the entire matcher.
I run Caddy with ENVIRONMENT=production ./caddy run --config ~/Desktop/Caddyfile
and hit the server with curl localhost:9080/dkfj
. I should receive the body Matched some or no expressions
since I haven’t provided the foo=bar
query parameter, but instead I receive Matched all expressions
.
I believe Caddy only supports a single expression
type matcher despite the doco indicating that:
Multiple matchers of the same type may be combined (e.g. multiple
path
matchers in the same set) using boolean algebra (AND/OR), as described in their respective sections below.
The section on the expression matcher doesn’t indicate that multiple expressions aren’t supported.
I had a crack at debugging Caddy, and I believe the problem is here:
d.tokens
contains tokens for both expressions, but it tries to parse both into a single statement (m.Expr
) which means the second expression overwrites the first one. Here’s a screenshot of the debug session:
You can see that while all expressions have been correctly parsed, only the ENVIRONMENT == "production"
expression is retained.
I admit that multiple expressions could be composed into a single compound expression; expression "{env.ENVIRONMENT} == \"production\" && {query.foo} == \"bar\""
in this case, but having them on separate lines helps with the clarity.
I’m happy to explore a potential fix (I understand the expression module is experimental, so I expected some rough edges) or maybe propose some changes to the documentation to make it clear that multiple expressions are not supported.