httpcaddyfile: Add RegisterDirectiveOrder
function for plugin authors
#5865
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.
We (@mholt @dunglas and I) were talking in Slack about the ergonomics of using the Caddyfile for end-users of custom builds of Caddy which may include many handler plugins. Forcing users to specify
order
or wrap things inroute
causes some friction that would be nice to smooth out.The reason we never did this in the past is because we didn't want to allow plugins to depend upon eachother, because we can't guarantee the order in which plugins are loaded. We also didn't want the ordering to become unreliable when the order of directives in the standard distribution changes.
We can mitigate those factors by doing two things:
defaultDirectiveOrder
which doesn't change, to ensure this, and modifydirectiveOrder
accordingly)order
global option allows) to reduce the chance of ordering that doesn't make sense.The API looks like this:
Or course, there's still a slight problem if two plugins try to both order the same way in relation to a standard directive (e.g. both are "before headers") because their order will not be guaranteed. There are some complicated ways we could mitigate this though, for example we could invalidate the ordering for both directives since they're in conflict, forcing the user to specify their own order for both. But ultimately I think this it probably not an immediate need, and we can expand upon that later.