Skip to content
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

map: Prevent output destinations overlap with Caddyfile shorthands #4657

Merged
merged 1 commit into from May 6, 2022

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Mar 23, 2022

Essentially, this tries to prevent configs like this:

example.com {
    map {host} {path} {
        example.com /example
    }
}

Where the output {path} is no good, because it's one of the placeholder shorthands. This means that the map destination would actually clobber an existing replacer output, and produce unexpected behaviour.

The implementation is kiiinda tricky though.

Since shorthand replacement happens before directive parsing (this surprised me when I was working on this, but "duh" I should've realized sooner), the map's Caddyfile parser actually sees {http.request.uri.path} instead of {path}; this means that we need to actually look for the replacements and map them back to the shorthand (for the error message).

With this change, the above Caddyfile will now spit out:

adapt: parsing caddyfile tokens for 'map': Caddyfile:2 - Error during parsing: destination {path} conflicts with a Caddyfile placeholder shorthand

Also, this adds {vars.*} shorthand. Nice to have now that we have a vars directive.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Mar 23, 2022
@francislavoie francislavoie added this to the v2.5.0 milestone Mar 23, 2022
@mholt mholt modified the milestones: v2.5.0, v2.5.1 Apr 13, 2022
francislavoie added a commit that referenced this pull request Apr 24, 2022
I'm yoinking this from my #4657 PR because I think we should get this in ASAP for v2.5.0 along with the new `vars` directive.
mholt pushed a commit that referenced this pull request Apr 25, 2022
…rt order (#4726)

* httpcaddyfile: Add `{vars.*}` placeholder shortcut

I'm yoinking this from my #4657 PR because I think we should get this in ASAP for v2.5.0 along with the new `vars` directive.

* Sort vars by matchers in reverse
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda awkward, but probably good to prevent a foot-gun. Thanks Francis

@mholt mholt merged commit f7be0ee into master May 6, 2022
@mholt mholt deleted the prevent-bad-map branch May 6, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants