Skip to content

Commit

Permalink
desktop: allow this client to be identified via user-agent
Browse files Browse the repository at this point in the history
Previously the HTTP requests were sent with a generic Go-http-client
user-agent which made it hard to determine where the requests are
coming from. It's important that we can find clients so that they
can be updated if APIs change in future.

Signed-off-by: David Scott <dave@recoil.org>
  • Loading branch information
djs55 committed Oct 15, 2024
1 parent 24c7872 commit a1f881a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/desktop/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ import (
"net/http"
"strings"

"github.com/docker/compose/v2/internal"
"github.com/docker/compose/v2/internal/memnet"
"github.com/r3labs/sse"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

// identify this client in the logs
var userAgent = "compose/" + internal.Version

// Client for integration with Docker Desktop features.
type Client struct {
apiEndpoint string
Expand Down Expand Up @@ -76,6 +80,7 @@ func (c *Client) Ping(ctx context.Context) (*PingResponse, error) {
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -105,6 +110,7 @@ func (c *Client) FeatureFlags(ctx context.Context) (FeatureFlagResponse, error)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -135,6 +141,7 @@ func (c *Client) GetFileSharesConfig(ctx context.Context) (*GetFileSharesConfigR
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -170,6 +177,7 @@ func (c *Client) CreateFileShare(ctx context.Context, r CreateFileShareRequest)
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -212,6 +220,7 @@ func (c *Client) ListFileShares(ctx context.Context) ([]FileShareSession, error)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand All @@ -236,6 +245,7 @@ func (c *Client) DeleteFileShare(ctx context.Context, id string) error {
if err != nil {
return err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return err
Expand Down Expand Up @@ -268,6 +278,7 @@ func (c *Client) StreamFileShares(ctx context.Context) (<-chan EventMessage[[]Fi
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
Expand Down

0 comments on commit a1f881a

Please sign in to comment.