1. My Caddy version (caddy version
):
v2.0.0-rc.3 h1:z2H/QnaRscip6aZJxwTbghu3zhC88Vo8l/K57WUce4Q=
2. How I run Caddy:
Caddy is kept running on my system via a macOS launchctl .plist file that executes caddy run --config /path/to/Caddyfile
as a background job.
a. System environment:
macOS Mojave 10.14.6 (18G4032)
b. Command:
caddy validate --config /path/to/config
d. My complete Caddyfile or JSON config:
localhost {
root * /Users/noel/Dev/server/projects-active/test
@request_b {
expression {http.request.cookie.testcookie} == "myvalue"
}
file_server browse {
root /Users/noel/Dev/server/projects-active/test/siteA
}
file_server @request_b browse {
root /Users/noel/Dev/server/projects-active/test/siteB
}
}
3. The problem I’m having:
I’m trying to set up a Caddy configuration where the presence of a cookie with a value will direct all requests to a separate site hosted on the same server. Unsure whether a separate file server directive, or a rewrite is the cleanest way to do this, but in either case, I’m having trouble getting a valid configuration when it comes to creating a named matcher to handle the check for the cookie. The above Caddyfile is a reduced test case that I am able to get the below error to reproduce with.
4. Error messages and/or full log output:
validate: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'subroute': provision http.handlers.subroute: setting up subroutes: route 1: loading matcher modules: module name 'expression': provision http.matchers.expression: compiling CEL program: ERROR: <input>:1:64: undeclared reference to 'myvalue' (in container '')
| caddyPlaceholder(request, "http.request.cookie.testcookie") == myvalue
| ...............................................................^
5. What I already tried:
Tried scanning the docs to see if there was another way to match a request cookie based on content but it seems like the expression matcher is the way to go on this one. What’s odd to me is even though I’m defining myvalue
in this case as a string, I’m the error I’m getting is an undeclared reference
, which shouldn’t matter, since I’m looking to match a string, no?