-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
httpcaddyfile: Improve directive sorting logic #3658
Conversation
root
directive sort orderc0160a1
to
ef802ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change and the tests!
Some logic needs to be corrected and we should probably include other directives that need to be sorted differently...
Actually... root
, along with the rewrite
and handle
directives are already mutually-exclusive of other instances of the same directive. I wonder if all of those would need to be added here, along with header
...
Hmm. Looks like we have a flaky test with the Caddyfile adapter. For some reason on some environments, the first |
httpcaddyfile: Delete test that no longer makes sense
72f0890
to
2895795
Compare
Co-authored-by: Matt Holt <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks for looking into this!
Note that the issue at https://caddy.community/t/v2-help-with-path-regexp-and-rewrite/9442 is not resolved by this because we don't (can't?) sort |
Actually it is resolved, because having a named matcher will now sort ahead of
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":8881"
],
"routes": [
{
"group": "group0",
"match": [
{
"path_regexp": {
"name": "bar",
"pattern": "^/z(.*)$"
}
}
],
"handle": [
{
"handler": "vars",
"root": "/bar"
}
]
},
{
"group": "group0",
"handle": [
{
"handler": "vars",
"root": "/foo"
}
]
},
{
"handle": [
{
"body": "Root: {http.vars.root}",
"handler": "static_response"
}
]
}
]
}
}
}
}
}
|
Ah, indeed, I was thinking more generally I guess, that this won't sort path_regexp matchers relative to path matchers. Will merge this in a sec. |
See discussion in https://caddy.community/t/v2-help-with-path-regexp-and-rewrite/9442/11
I'm pretty sure that it's almost always incorrect to sort
root
handlers from the Caddyfile in the same order as other directives, because it's essentially setting a variable, so only the last one run will apply - so you want the last one run to be the most-specific one.Also, see the discussion in https://caddy.community/t/presenting-different-content-based-on-origin-of-request/9467/7
If a directive has any kind of matcher, it should still sort before a directive of the same name with no matcher at all.