How to set a response header for every route

1. Caddy version (caddy version):


2. How I run Caddy:

As go library in an application

a. System environment:

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
Make sure the backticks stay on their own lines.

3. The problem I’m having:

I’m using the json version for the configuration file and just want to know how can I set a header field to a specific value ONCE for EVERY route I have defined under routes

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Can you be more specific? What have you already tried? Most of the help template is empty so it makes it hard for us to help you :frowning:

Hi Matt,

The reason I haven’t added more is that I’m struggling to know where I should even start. I just find the documentation for the json format very non-intuitive and usually only make progress when I find some related example somewhere which then allows me to actually understand the docs. It’s most likely just the way my brain is wired.

I really like working with Caddy and now use it for pretty much any Go project with an http component, but I have also spent hours crawling the web to make sense on the configuration settings.

Please close the issue if you think if this is below the standard of what’s expected of an issue. It’s not a showstopper for me as there is a brute force work around.

Have you tried using the Caddyfile? JSON config is the “advanced” way of using Caddy.

But like Matt said, if you don’t show us what you current config looks like, we can’t really suggest anything.

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