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

Placeholder shorthands are not replaced in named routes #5788

Closed
pkoenig10 opened this issue Aug 28, 2023 · 3 comments · Fixed by #5791
Closed

Placeholder shorthands are not replaced in named routes #5788

pkoenig10 opened this issue Aug 28, 2023 · 3 comments · Fixed by #5791
Labels
bug 🐞 Something isn't working

Comments

@pkoenig10
Copy link
Contributor

The following Caddyfile:

&(named) {
    vars Test {header.test}
}

example.com {
    invoke named
    vars Test {header.test}
}

Produces the following config:

{
    "apps": {
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        ":443"
                    ],
                    "routes": [
                        {
                            "match": [
                                {
                                    "host": [
                                        "example.com"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "Test": "{http.request.header.test}",
                                                    "handler": "vars"
                                                },
                                                {
                                                    "handler": "invoke",
                                                    "name": "named"
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ],
                            "terminal": true
                        }
                    ],
                    "named_routes": {
                        "named": {
                            "handle": [
                                {
                                    "Test": "{header.test}",
                                    "handler": "vars"
                                }
                            ]
                        }
                    }
                }
            }
        }
    }
}

I see that named routes are still an experimental feature, so I'm not sure if this behavior is intentional or a known limitation.

If this is not a bug, I think it would be helpful to call out in the documentation. It took me while to debug why my placeholders were not working as I would have expected.

@francislavoie
Copy link
Member

That does seem like a bug. Interesting.

@hainenber
Copy link
Contributor

I discovered that the named_routes blocks don't go through substitution of placeholder shorthands, as with the origin server blocks (source). The fix is to have the named_routes undergo same treatment.

I've made a draft PR here. Please have a look. Thanks!

@mholt
Copy link
Member

mholt commented Sep 7, 2023

Cool, thank you for taking initiative on this while we've been busy @hainenber! We appreciate your contribution.

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 a pull request may close this issue.

4 participants