Do multiple handle directives at the same level execute together if they share the same matcher?

1. The problem I’m having:

Hello!

The documentation of the handle directive mentions the following:

Testing, I saw that if I set, for example, the following configuration both handle directives are executed and the response contains the two headers, Hello and Hola.

(docker-service) {
	import log {args[0]}

	@{args[1]} host {args[0]}

	handle @{args[1]} {
		import security
		import compression

		handle /get {
			header Hello hello
		}

		handle /get {
			header Hola hola
		}

		reverse_proxy {args[1]}:{args[2]}
	}
}

Does this mean that, even though the handle directives that are at the same level are mutually exclusive, if the matcher is the same, are they going to be merged into a single directive and therefore both headers are sent?

The behavior I expected is that only a single header would be sent, since only a single handle directive would be executed.

Thanks in advance.

2. Error messages and/or full log output:

-

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

Using Docker and Docker Compose .

5. Links to relevant resources:

-

Yes; I believe we consolidate handle blocks that have the exact same matching parameters. (I haven’t looked at this code in a long time, just trying to go from memory.)

You can verify with the output of caddy adapt – if it’s identical whether you have 1 block or 2, then there’s your answer. :slight_smile:

1 Like

Yep we merge handle with the same matcher. But writing a config where they have the same matcher is kinda weird. What usecase makes sense where you would want two handle with the same matcher? The second one would always be shadowed by the first, so what’s the point?

2 Likes

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