Fix headers not showing when set_headers included

This commit is contained in:
akp 2024-10-10 13:15:54 +01:00
parent 972ff18012
commit 4462f9ce63
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

View file

@ -39,27 +39,39 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
),
}
var setHeaders bool
if h.Next() {
if h.Val() == "set_headers" {
handlers = append(handlers, caddyconfig.JSONModuleObject(
&headers.Handler{
Request: &headers.HeaderOps{
Set: http.Header{
"X-Tailscale-ID": []string{"{http.auth.user.id}"},
"X-Tailscale-Display-Name": []string{"{http.auth.user.display_name}"},
"X-Tailscale-Login-Name": []string{"{http.auth.user.login_name}"},
},
},
},
"handler",
"headers",
nil,
))
setHeaders = true
} else {
return nil, h.Errf("unknown argument %#v", h.ValRaw())
}
}
headerOps := new(headers.HeaderOps)
// If both the Set and Delete are set at the same time, Delete will take priority and prevent any headers from being
// included in the request so we have to only do one or the other
if setHeaders {
headerOps.Set = http.Header{
"X-Tailscale-ID": []string{"{http.auth.user.id}"},
"X-Tailscale-Display-Name": []string{"{http.auth.user.display_name}"},
"X-Tailscale-Login-Name": []string{"{http.auth.user.login_name}"},
}
} else {
headerOps.Delete = []string{"X-Tailscale-Id", "X-Tailscale-Display-Name", "X-Tailscale-Login-Name"}
}
handlers = append(handlers, caddyconfig.JSONModuleObject(
&headers.Handler{
Request: headerOps,
},
"handler",
"headers",
nil,
))
if h.NextArg() {
return nil, h.Err("too many arguments")
}