Where are the variables usable when adding extra headers?

I would like to add an extra header in my proxy call to the upstream server (Caddy V2). To do that I can use header_up

reverse_proxy localhost:9000 {
	header_up Hello-World "Bonjour everyone!"
}

(I will be using the API to configure the routes, so this will be the JSON version, appropriate for the API)

I need however to add a header X-Real-IP which has the value of the calling client - the value which is added to X-Forwarded-For.

Where is this value stored? And generally speaking - is there a list of all the variables which are usable when the call goes though the various layers?

OK - I think I found the place: https://caddyserver.com/docs/caddyfile/concepts#placeholders

In my case this is {http.request.remote} {http.request.remote.host} (otherwise I get host+port).

Note for future readers (including myself): the word to search for is “placeholders”.

1 Like

Unfortunately the list of placeholders is a bit scattered because each module provides their own. For the HTTP app, the complete list is here:

The page you linked is the list of placeholders that the Caddyfile provides shortcuts for, not necessarily the full list of placeholders available.

In your case, you can use {remote_host} instead of {http.request.remote.host} because of the Caddyfile shortcut existing.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.