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

Feature-Request: Placeholder with default value #1793

Open
blaubaer opened this issue Jul 29, 2017 · 5 comments · May be fixed by #5275
Open

Feature-Request: Placeholder with default value #1793

blaubaer opened this issue Jul 29, 2017 · 5 comments · May be fixed by #5275
Labels
feature ⚙️ New feature or request help wanted 🆘 Extra attention is needed
Milestone

Comments

@blaubaer
Copy link

blaubaer commented Jul 29, 2017

If there is no/empty for a placeholder use default/fallback value/placeholder.

Acceptance Test

Pattern

{foo:-{bar}}

Expectations

foo bar Result
John Mark John
John empty John
empty Mark Mark
empty empty empty

Usage example

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

If this caddy is also behind a reverse proxy it also will set the header X-Forwarded-Path ... in this case use this header. If not set we expect to be not behind a reverse proxy and directly called ... in this case use path.

Other software which uses this pattern

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

@mholt mholt added the feature ⚙️ New feature or request label Jul 29, 2017
@mholt
Copy link
Member

mholt commented May 9, 2019

Will be mostly irrelevant in Caddy 2, which provides this capability through other means.

@yesiyan01
Copy link

Any updates on this one?

@francislavoie
Copy link
Member

francislavoie commented Mar 19, 2021

@yesiyan01 what exactly are you looking for? Could you be more specific? What you want is probably possible another way.

@yesiyan01
Copy link

@francislavoie

I have a reverse proxy handler that overrides authorization header e.g.

handler: reverse_proxy
headers:
  request:
    set:
      Authorization:
        - '{http.oauth1}'
transport:
   protocol: http
   tls: {}
upstreams:
   - dial: 'xxx.com:443'

where 'http.oauth1' is a custom header value set from a custom module.

I'd like the ability to use 'http.oauth1' in the placeholder but fallback to a static API-KEY when http.oauth1 is not present.

@francislavoie
Copy link
Member

francislavoie commented Mar 19, 2021

Thanks for the example!

The changes would need to be made to https://github.com/caddyserver/caddy/blob/master/replacer.go, if you'd like to take a crack at it.

We recently implemented defaults for environment variables in the Caddyfile, so I think we should follow suit in this case and use the same syntax, i.e. : as the delimiter for the default value.

This change would need to be thoroughly tested (see replacer_test.go)

@mholt mholt changed the title Feature-Request: Placeholder with default handling Feature-Request: Placeholder with default value Jul 14, 2021
@mholt mholt added the help wanted 🆘 Extra attention is needed label Sep 13, 2022
JensErat added a commit to mercedes-benz/caddy that referenced this issue Dec 29, 2022
Support variable expansion also in placeholders, like in
`{unsetPlaceholder:default value}`. Implemented similarly to caddyserver#3682,
which provided defaults for environment variable expansion.

Closes caddyserver#1793.

Signed-off-by: Jens Erat <[email protected]>
@JensErat JensErat linked a pull request Dec 29, 2022 that will close this issue
3 tasks
JensErat added a commit to mercedes-benz/caddy that referenced this issue Feb 7, 2023
Support variable expansion also in placeholders, like in
`{unsetPlaceholder:default value}`. Implemented similarly to caddyserver#3682,
which provided defaults for environment variable expansion.

Closes caddyserver#1793.

Signed-off-by: Jens Erat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request help wanted 🆘 Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants