Skip to content

httpcaddyfile: no warning on duplicate named routes #7798

Closed

Description

@vijayvenkatj

Issue Details

I noticed that there were no warnings on duplicate named_routes in the Caddyfile. A warning would have made this configuration mistake much easier to spot.

Reproduction

&(api) {
	header X-Version v1
	respond "API v1"
}

&(api) {
	header X-Version v2
	respond "API v2"
}

localhost {
	invoke api
}

Current behaviour

The second named route definition silently replaces the first one. ( Last Write Wins ).
The adapted JSON contains only the last definition, indicating that the original route has been overwritten during adaptation.

"named_routes":{"api":{"handle":[{"handler":"headers","response":{"set":{"X-Version":["v2"]}}}]}}

Proposed fix

When a duplicate named route is encountered, log a warning indicating that an existing named route exists.

Assistance Disclosure

AI used

If AI was used, describe the extent to which it was used.

I used ChatGPT to create a sample Caddyfile to demonstrate this issue instead of using my original configuration, which contained personal details.

Activity

  1. vijayvenkatj commented on Jun 4, 2026

    @vijayvenkatj
    ContributorAuthor

    I took a look at this and noticed that extractNamedRoutes appears to be a reasonable place to log the warning, since duplicate named routes are detected there. If this approach sounds good, I'd be happy to open a PR on this.

  2. francislavoie commented on Jun 4, 2026

    @francislavoie
    Member

    Yeah sounds reasonable to make it an error to redefine a named route.

  3. vijayvenkatj commented on Jun 4, 2026

    @vijayvenkatj
    ContributorAuthor

    Yeah sounds reasonable to make it an error to redefine a named route.

    Should'nt It be a warning since It doesn't do any harm?

  4. francislavoie commented on Jun 4, 2026

    @francislavoie
    Member

    Well like you pointed out it clobbers the first route, so I think making it an error is a much stronger signal of a problem. A lot of people ignore warnings unfortunately.

  5. vijayvenkatj commented on Jun 4, 2026

    @vijayvenkatj
    ContributorAuthor

    Makes sense, I would like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions