chore(cli): correctly report telemetry even when transport replaced (#7670)

By introducing the "ExtraHeaders" map, we can apply headers even when
handlers replace the transport, as in the case of our scaletests.

Also, only send telemetry header when it's small.
This commit is contained in:
Ammar Bandukwala
2023-05-31 00:11:56 +00:00
committed by GitHub
parent 867996aa18
commit 43eee35ae8
4 changed files with 54 additions and 34 deletions
+8 -2
View File
@@ -85,8 +85,9 @@ var loggableMimeTypes = map[string]struct{}{
// New creates a Coder client for the provided URL.
func New(serverURL *url.URL) *Client {
return &Client{
URL: serverURL,
HTTPClient: &http.Client{},
URL: serverURL,
HTTPClient: &http.Client{},
ExtraHeaders: make(http.Header),
}
}
@@ -96,6 +97,9 @@ type Client struct {
mu sync.RWMutex // Protects following.
sessionToken string
// ExtraHeaders are headers to add to every request.
ExtraHeaders http.Header
HTTPClient *http.Client
URL *url.URL
@@ -189,6 +193,8 @@ func (c *Client) Request(ctx context.Context, method, path string, body interfac
return nil, xerrors.Errorf("create request: %w", err)
}
req.Header = c.ExtraHeaders.Clone()
tokenHeader := c.SessionTokenHeader
if tokenHeader == "" {
tokenHeader = SessionTokenHeader