Header manipulation with multiple values for a same key

Hi there,

I have a Caddy 2 instance that runs in front of an architecture. This works very well.

By default, each response includes two server headers due to the different proxies the response goes through:

server: Caddy
server: Google Frontend

The issue I have is with header manipulation. I would like to remove all server headers and set a single custom server header value when the response is returned by Caddy. For instance:

server: My Custom Value

I tried different syntaxes but it seems that I can only remove all or add one.

For instance, this syntax is removing all server headers but not adding the custom one:

header {
    +server "My Custom Value"

It seems also that find/replace is not working. The following has no effect:

header {
    server "Google Frontend" "My Custom Value" 

This happens with Caddy 2.3.0.

I guess something is wrong with the syntax I use or maybe this use case is not supported? Looking at the docs I cannot understand what’s wrong. Any ideas?

Does simply:

header Server "My Custom Value"

not do what you want then?

@matt Thanks for your help. Unfortunately, no. When I do that, I end up with the following as response headers:

server: My Custom Value
server: Google Frontend

However, following your comment I got what the problem is. My Caddy setup also makes use of a reverse_proxy directive. Since the header server: Google Frontend comes from the reverse proxy call, I need to configure this header deletion using the reverse_proxy block. Here is the working configuration:

:443 {
    header server "My Custom Value"
    reserve_proxy https://example.com {
        header_down -server

Yep, that’s one way. Another way is to defer header operations until writing the response. Anyway, Glad you figured it out.

This is why our forum rules require filling out the help template completely. Knowing this information would have made the answer obvious right away.

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