MCPcopy Index your code
hub / github.com/docker/docker-agent / NewHTTPClient

Function NewHTTPClient

pkg/httpclient/client.go:32–56  ·  view source on GitHub ↗
(ctx context.Context, opts ...Opt)

Source from the content-addressed store, hash-verified

30type Opt func(*HTTPOptions)
31
32func 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)`

Callers 8

NewClientFunction · 0.92
NewClientFunction · 0.92
NewClientFunction · 0.92
NewClientFunction · 0.92
ListModelsFunction · 0.92
ReadMethod · 0.92
fetchProviderModelsFunction · 0.92
doRequestWithCtxFunction · 0.85

Calls 3

newTransportFunction · 0.85
WrapWithOTelFunction · 0.85
SetMethod · 0.45

Tested by 1

doRequestWithCtxFunction · 0.68