Send custom headers for live queries (#8991)

This needed to be set specifically for the live query websocket dialer,
since that doesn't use the HTTP client that the rest of the API client
methods use.

Co-authored-by: Tomas Touceda <chiiph@gmail.com>
This commit is contained in:
Zach Wasserman
2022-12-12 07:56:35 -08:00
committed by GitHub
co-authored by Tomas Touceda
parent a6d3938182
commit 083b781c2c
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
* Fix `fleetctl query` to use custom HTTP headers if configured.
+6 -1
View File
@@ -91,7 +91,12 @@ func (c *Client) LiveQueryWithContext(ctx context.Context, query string, labels
wssURL.Scheme = "ws"
}
wssURL.Path = c.urlPrefix + "/api/latest/fleet/results/websocket"
conn, _, err := dialer.Dial(wssURL.String(), nil)
// Ensure custom headers (set by config) are added to websocket request
headers := make(http.Header)
for k, v := range c.customHeaders {
headers.Set(k, v)
}
conn, _, err := dialer.Dial(wssURL.String(), headers)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "upgrade live query result websocket")
}