All directives are rejected (except copy_response_headers) in handle_response section

1. The problem I’m having:

Use Caddyfile to add header in handle_response section of reverse_proxy but adapter rejects the configuration.

2. Error messages and/or full log output:

Error: parsing caddyfile tokens for 'reverse_proxy': unrecognized directive: header_down - are you sure your Caddyfile structure (nesting and braces) is correct?, at /etc/caddy/Caddyfile:15

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/gpg.key’ | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt’ | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

a. System environment:

Ubuntu 24.04 in WSL2

b. Command:

caddy adapt --adapter="caddyfile" --config="/etc/caddy/Caddyfile" --pretty --validate

c. Service/unit/compose file:

not relevant

d. My complete Caddy config:

{
    debug
}

:3001 {
	log {
		output file /var/log/caddy/year2024-access.log
	}

	reverse_proxy localhost:3000 {
		@setcookie header Set-Cookie *
		handle_response @setcookie {
			header_down +X-Some-Header-Down {rp.header.Set-Cookie}
			copy_response_headers
		}
	}
}

5. Links to relevant resources:

header_down isn’t a directive, it’s a subdirective of reverse_proxy. In other words, it’s only valid directly under reverse_proxy, not within handle_response which takes directives.

If you’re trying to add a header to the response, use header.

What subdirectives other than copy_response_headers can be used in handle_response of reverse_proxy? Thanks for helping.

No subdirectives of reverse_proxy at all can appear in handle_response. Only directives, plus as a special case, copy_response and copy_response_headers (as documented on reverse_proxy (Caddyfile directive) — Caddy Documentation)

In fact, i tried log_append in handle_response of reverse_proxy and it was rejected too. Should log_append be a directive and should it be allowed? Thanks again.

Show the error you got, and the config you tried.

Sorry, my fault. log_append works with handle_response. Thanks for helping.

1 Like

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