I’m trying to add some headers to my Caddy files, and everything works fine, as expected, but the headers I’m adding tend to get quite long. For example the Feature-Policy header, or the Content-Security-Policy header.
Is there a way in a Caddy config file to split the header across multiple lines to make it easier to read/edit?
I know you can use a + in front of a header name to append another header of the same name, but what I want to know is if there’s a way to define a single header over multiple lines but have it sent from the server as a single line?
If there isn’t then that’s fine, but it would just make long header values easier to read if it were possible.
Thanks for the example, but unfortunately this is one of the things I tried and it doesn’t seem to work.
When I put all of the values onto a single line I can see the header in the Chrome network tab, but when I split it over multiple lines like that it stops appearing.
whitestrake at apollo in ~/Projects/test
❯ caddy -version
Caddy 0.11.0 (unofficial)
whitestrake at apollo in ~/Projects/test
❯ cat Caddyfile
:2015 {
status 200 /
header / {
X-My-Test-Header "This is
a multiline
header for
testing."
}
}
whitestrake at apollo in ~/Projects/test
❯ caddy
Activating privacy features... done.
http://:2015
From another terminal:
whitestrake at apollo in ~
❯ curl -IL http://localhost:2015/
HTTP/1.1 200 OK
Server: Caddy
X-My-Test-Header: This is a multiline header for testing.
Date: Tue, 25 Sep 2018 23:05:48 GMT
The relevant docs outlining the behaviour of tokens and quotes:
I modified my earlier attempt to add a HTTPS listener and was able to replicate the issue. Looks like we’ve got a bug.
The header doesn’t appear when:
The header content is given as a multiline token in the Caddyfile, AND;
The site is accessed over HTTPS
A single-line header works over HTTPS and both work over HTTP. Very strange. Time to take this to the Github issue tracker so we can investigate the cause, I think.
I was just testing the multiline headers and for me it does work, but I noticed the all the spaces from the indentation of the multiline header is also in the response (make kinda sense):
There is no way to remove the additional spaces, other than not including them in your Caddyfile. The extra spaces don’t impact header function whatsoever, and the Caddyfile parser treats the whole string from opening quote to closing quote as a single token, feeding it to the header directive without modification (such as stripping spaces).