| 30 | type Opt func(*HTTPOptions) |
| 31 | |
| 32 | func NewHTTPClient(ctx context.Context, opts ...Opt) *http.Client { |
| 33 | httpOptions := HTTPOptions{ |
| 34 | Header: make(http.Header), |
| 35 | cagentID: userid.Get, |
| 36 | } |
| 37 | |
| 38 | for _, opt := range opts { |
| 39 | opt(&httpOptions) |
| 40 | } |
| 41 | |
| 42 | // Enforce a consistent User-Agent header |
| 43 | httpOptions.Header.Set("User-Agent", fmt.Sprintf("Cagent/%s (%s; %s)", version.Version, runtime.GOOS, runtime.GOARCH)) |
| 44 | |
| 45 | // Disable automatic gzip: Go's default transport transparently compresses |
| 46 | // and decompresses responses, which is incompatible with SSE streaming. |
| 47 | // See https://github.com/docker/docker-agent/issues/1956 |
| 48 | rt := newTransport(ctx) |
| 49 | |
| 50 | return &http.Client{ |
| 51 | Transport: WrapWithOTel(&userAgentTransport{ |
| 52 | httpOptions: httpOptions, |
| 53 | rt: &sseFilterTransport{base: rt}, |
| 54 | }), |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // otelEnabled tracks whether the OTel SDK has been initialised in this |
| 59 | // process. `cmd/root/otel.go:initOTelSDK` calls `SetOTelEnabled(true)` |