root: Set Helper.State for other directives/plugins to use#7594
root: Set Helper.State for other directives/plugins to use#7594henderkes wants to merge 4 commits intocaddyserver:masterfrom
Conversation
| return nil, h.ArgErr() | ||
| } | ||
| // store the unmatched root in state so other directives can access it | ||
| if userMatcherSet == nil { |
There was a problem hiding this comment.
| return nil, h.ArgErr() | ||
| } | ||
| // store the unmatched root in state so other directives can access it | ||
| h.State["root"] = h.Val() |
There was a problem hiding this comment.
we have both accesses with strings and with constants (e.g. namedRoute), so I wasn't sure if I should add one here
|
Overwriting |
php_server directive|
Worth noting though, this could misbehave: I'm not 100% sure but needs checking. |
You're right, that breaks it, it overwrites the root to /bar. |
…t among sibling directives
:80 {
root * public # * optional
handle_path /bar* {
root bar # gets initial copy of State, but later changes to parent may not be picked up?
php_server { # sibling to php_server, sharing State
worker index.php
}
}
php_server { # sibling to root directive, sharing State
env APP_ENV test
worker index.php
}
}This works for our purposes now, but I am not sure if the lack of later propagation of parent -> child could cause an issue. You're more familiar with the ways the Caddyfile is parsed and what may need access to later-updated values in the State. Although it kind of feels weird to me that this was the behaviour in the first place. Edit: also, since this is a shallow copy, point values in the existing map would still be shared. Should I change this to a deep copy instead? |
|
I didn't even remember we had A quick scan of the existing usages suggest it's only used for server-level config stuff like I think it could break caddy/caddyconfig/httpcaddyfile/httptype.go Lines 164 to 169 in 5d189af |
|
Maybe it would be better to introduce a new |
|
Thank you for the suggestion, but I think we'd all want to avoid duplicating that map if there's any helping it. It's too late tonight, but I'll try to figure out how this could potentially cause issues (or first verify whether invoke does). Can't hurt to get a bit more familiar with Caddy. |
The real question is what plugins do, outside of Caddy itself. I don't know if any of the would use State in a way where propagation back to the parent matters, but I assume it might. Unfortunately, creating a BlockState for things that should not carry back up seems to be the only way to prevent breakage for sure. The question is whether it wouldn't be easier to just expose the |
Assistance Disclosure
No AI was used.
I feel like it may be useful to also generate warnings in case a
rootstatement overwrites an existing one, e.g.But that may be a separate discussion.