Placeholders with default handling?

Hi!

Is there a possibility to use something like:

{foo:-{bar}}

Why? I want a fallback to {bar} if there is no {foo}.

Example

proxy /api my-api:80 {
    transparent
    websocket
    without /api
    header_upstream X-Forwarded-Path {>X-Forwarded-Path:-{path}}
}

References

https://logback.qos.ch/manual/configuration.html#defaultValuesForVariables

I don’t think there’s a way to do that, actually. You might have to request this feature at the Caddy Github.

I imagine this could be a relatively simple change to the httpserver replacer logic to allow this kind of fallback for an empty placeholder.

1 Like

Good idea. I opened https://github.com/mholt/caddy/issues/1793.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.