TUN-7564: Support cf-trace-id for cloudflared access

This commit is contained in:
Devin Carr 2023-07-05 14:26:19 -07:00
parent 8a3eade6d3
commit ccad59dfab
2 changed files with 5 additions and 4 deletions

View File

@ -148,9 +148,9 @@ func ssh(c *cli.Context) error {
func buildRequestHeaders(values []string) http.Header {
headers := make(http.Header)
for _, valuePair := range values {
split := strings.Split(valuePair, ":")
if len(split) > 1 {
headers.Add(strings.TrimSpace(split[0]), strings.TrimSpace(split[1]))
header, value, found := strings.Cut(valuePair, ":")
if found {
headers.Add(strings.TrimSpace(header), strings.TrimSpace(value))
}
}
return headers

View File

@ -12,7 +12,8 @@ func TestBuildRequestHeaders(t *testing.T) {
headers.Add("client", "value")
headers.Add("secret", "safe-value")
values := buildRequestHeaders([]string{"client: value", "secret: safe-value", "trash"})
values := buildRequestHeaders([]string{"client: value", "secret: safe-value", "trash", "cf-trace-id: 000:000:0:1:asd"})
assert.Equal(t, headers.Get("client"), values.Get("client"))
assert.Equal(t, headers.Get("secret"), values.Get("secret"))
assert.Equal(t, headers.Get("cf-trace-id"), values.Get("000:000:0:1:asd"))
}