Vars and map not visible in the plugin?

1. The problem I’m having:

I am trying to use a variable to build a custom key for a cache plugin - this is not yet merged by @darkweak.

While testing the PR I noticed that my variable is not seen by the plugin, although it is available to be sent as additional custom header.

I also tried to set the variable through vars with the same result.

Am I missing something? Did I misread the caddy order?

2. Error messages and/or full log output:

$ curl -IX GET "test.example.local/gg/dd?aa=11&rr=22"
HTTP/1.1 200 OK
Cache-Control: public
Cache-Status: Souin; fwd=uri-miss; stored; key=/gg/dd
Content-Length: 25
Content-Type: text/html; charset=utf-8
Custom-Cache-Key: /gg/dd?aa=11&rr=22

3. Caddy version:

2.7.6

4. How I installed and ran Caddy:

a. System environment:

docker compose.

b. Command:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

services:
  proxy:
    image: caddy:souin
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"
    volumes:
    - ./etc/caddy:/etc/caddy
    - ./var/config:/config
    - ./var/data:/data
    - ./var/logs:/logs
    - /var/run/docker.sock:/var/run/docker.sock:ro
    working_dir: /etc/caddy

d. My complete Caddy config:

{
	order cache before rewrite

	debug
	log {
		output file /logs/main.log
		format json {
			time_format iso8601
		}
	}
	local_certs
	cache {
		default_cache_control public
	}
}

:80 {
	header Content-Type "text/html; charset=utf-8"
	respond "Nothing here... Yet??????"
}

http://test.example.local {
	map {http.request.uri.query} {cacheKey} {
		~^(.*)(?:[?&]some_id=[^&]*)$ "?${1}"
		~^(some_id=[^&]*&?)(.*)$ "?${2}"
		~^([^&]*)(&some_id=[^&]*)(&?.*)$ "?${1}${3}"
		~^$ ""
		~^(.+)$ "?${1}"
	}
	header Custom-Cache-Key {http.request.uri.path}{cacheKey}
	header Content-Type "text/html; charset=utf-8"
	respond "Nothing here... Yet??????"
	cache {
		key {
			template {http.request.uri.path}{cacheKey}
		}
	}
}

5. Links to relevant resources:

This was resolved by @darkweak in the PR mentioned above.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.