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

httpcaddyfile: Fix sorting edgecase for nested handle_path #4477

Merged
merged 1 commit into from
Dec 13, 2021

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Dec 12, 2021

Fixes a bug reported in https://caddy.community/t/handle-path-being-ignored-when-paired-with-handle-in-same-block/14393

We had some code in ServerType.Setup() that would ensure handle_path has the same sort level as handle, but we were missing the same check in parseSegmentAsConfig to make sure that works properly inside of any nested subroute (handle, route, handle_errors, handle_response).

To be clear, the fix is copy-paste from another spot where we do the same thing:

// As a special case, we want "handle_path" to be sorted
// at the same level as "handle", so we force them to use
// the same directive name after their parsing is complete.
// See https://github.com/caddyserver/caddy/issues/3675#issuecomment-678042377
if dir == "handle_path" {
dir = "handle"
}

The new test fails before the change (the handle_path ends up after the handle in the same level, and they're missing a group name because the group is omitted if there's no two handlers with the same level) and passes after.

@francislavoie francislavoie added bug 🐞 Something isn't working under review 🧐 Review is pending before merging labels Dec 12, 2021
@francislavoie francislavoie added this to the v2.5.0 milestone Dec 12, 2021
@francislavoie francislavoie requested a review from mholt December 12, 2021 17:37
@adityaxdiwakar
Copy link

OP from the community thread, thank you very much @francislavoie. You guys are fast! Glad I switched to Caddy.

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.

Thanks for the fix. Hmm, unfortunate that we need to repeat that logic. I wonder if there's any way to combine the other function where this is from with this logic. 🤔 (Maybe for another PR, if so.)

Can we move the change any lower? The only next use of dir is on L352, other than in an error message earlier on L349. It'd be helpful if the directive in the error message is the same as appears in the config. So I wonder if we move this change to between, say, L350-351 it might be a little more helpful.

@francislavoie
Copy link
Member Author

Yeah we should extract this to a method to do these kinds of normalizations. I'll move it.

@francislavoie francislavoie force-pushed the sort-nested-handle-path branch from dc56336 to ec2d357 Compare December 13, 2021 18:36
@francislavoie francislavoie requested a review from mholt December 13, 2021 18:36
@francislavoie
Copy link
Member Author

Updated

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.

That looks better. Thanks!

@francislavoie francislavoie merged commit 81ee34e into master Dec 13, 2021
@francislavoie francislavoie deleted the sort-nested-handle-path branch December 13, 2021 18:42
@mholt mholt removed the under review 🧐 Review is pending before merging label Dec 13, 2021
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.

3 participants