httpcaddyfile: Rewrite root
and rewrite
parsing to allow omitting matcher
#5844
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had this idea from reviewing @dunglas's code recently (where he copy-pasted some code from the Caddy codebase itself). The
php_fastcgi
directive usesRegisterDirective
to get full control of parsing, instead of theRegisterHandlerDirective
shortcut which does automatic request matcher parsing.That made me realize we can do the same for
root
, and that we could actually makeroot /srv
work, instead of the awkwardroot * /srv
with an explicit*
matcher) that we've been stuck with since v2.0.Nice and simple, just a small rewrite of the parsing to count the number of arguments first, and if we have only one argument then we can assume it's the actual root path and that there's no matcher, because it never makes sense to ever only pass a matcher to
root
and no root path.Added a test to cover the happy path, and tested the 0 and 3+ argument cases by hand quickly.
Before:
After:
🎉