Fix headers not showing when set_headers included
This commit is contained in:
parent
972ff18012
commit
4462f9ce63
1 changed files with 26 additions and 14 deletions
40
caddyfile.go
40
caddyfile.go
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue