caddyserver / caddyserver/website

Update directive sorting order description for clarity

Open
#472 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
227
Forks
213
Avg merge
3h 52m
Merged PRs (30d)
1

Description

Document here https://caddyserver.com/docs/caddyfile/directives#directive-order says:

Same-named directives are sorted according to their matchers.

The highest priority is a directive with a single path matcher.

A directive with any other matcher is sorted next, in the order it appears in the Caddyfile. This includes path matchers with multiple values, and named matchers.

Based on the description, one would logically assume that, when sorting same named directive, like handle under the same site block, like:

example.com {
    @UA header User-Agent *something*
    handle @UA {
        reverse_proxy 127.0.0.1:8080
    }
    handle /path1 {
        reverse_proxy 127.0.0.1:8081
    }
    handle /path2 {
        reverse_proxy 127.0.0.1:8082
    }
}

path1 and path2 would have highest priority, after all they have a single path matcher. @UA as a named matcher would be sorted next, based on the order it appeared in the caddyfile.

However in reality, the @UA matcher is the first one to be handled, which contradicts what is being said in the documents.

On the forum a dev told me that (https://caddy.community/t/confusion-about-directive-order/30985):

If they’re different, the matcher defined first stays before the other. https://github.com/caddyserver/caddy/blob/master/caddyconfig%2Fhttpcaddyfile%2Fdirectives.go#L496-L500

Maybe, the document could use some touch up for clarity regarding the sorting order?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the directive order section at https://caddyserver.com/docs/caddyfile/directives#directive-order and compare its wording with the sorting behavior described in the issue. Review the linked directives.go lines and forum explanation, then update the documentation so the ordering rules and the handle example are unambiguous.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.