Caddy: remove headers not working for header_downstream in proxy

Created on 1 Nov 2016  路  4Comments  路  Source: caddyserver/caddy

1. What version of Caddy are you running (caddy -version)?

0.9.3

2. What are you trying to do?

remove a header when using caddy to proxy

3. What is your entire Caddyfile?

http://example.com:881 {
proxy / http://localhost:3333 {
    header_downstream -server
   }
}

4. How did you run Caddy (give the full command and describe the execution environment)?

via systemd because I like to maintain my own /usr/local/lib/systemd/system/caddy.service.

5. What did you expect to see?

caddy to start, and the server header to be removed from proxy'd responses.

6. What did you see instead (give full error messages and/or log)?

caddy refuses to start, and the following error is logged:

Parse error: Wrong argument count or unexpected line ending after '-server'

When removing a header, the value should be optional; it seems that caddy thinks its mandatory.

header_downstream name value

should really be

header_downstream { ["+"]name value | "-"name }

If I provide a bogus second parameter, i.e. header_downstream -server bogus in my caddy file, then caddy starts and will quite happily update the server header, but replaces it with the default of "Caddy" instead of removing it. As a temporary solution I do header_downstream server Apache to simply overwrite what the proxy is returning, but ideally -server would work to remove the entry.

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

bug

All 4 comments

  1. I think this header_downstream { ["+"]name value | "-"name } is reasonable. Will work out a patch soon.
  2. For replacing with the default of Caddy header. What about the status code? (200? 404?)
  1. Excellent. BTW, I was assuming that this should be the behavior as that's whats documented in the proxy documentation in the user guide.
  2. The status code is 200, so everything seems to work just fine. I'm guessing that when doing header_downstream -server whatever the code does the equivalent of (whether deliberate or accidental) of header_downstream Server Caddy. I suspect that this is accidental because there are a few other occasions where this happens.
  1. Done.
  2. I think I find the reason. This header (Server Caddy) is preset by caddy before proxy. The header_downstream only influence the headers of proxy backend's response. So I think you should use header -Server instead.

Oh, yes, that's correct -- header_downstream -Server will remove a header coming back downstream but not affect headers set by the local instance. I think keeping those two controls separate is an important distinction.

Was this page helpful?
0 / 5 - 0 ratings