mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
+8
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user