@@ -4,13 +4,11 @@ import (
44 "context"
55 "fmt"
66 "maps"
7- "net"
87 "net/http"
98 "net/url"
109 "runtime"
1110
12- "github.com/docker/docker-agent/pkg/desktop"
13- socket "github.com/docker/docker-agent/pkg/desktop/socket"
11+ "github.com/docker/docker-agent/pkg/remote"
1412 "github.com/docker/docker-agent/pkg/version"
1513)
1614
@@ -21,7 +19,7 @@ type HTTPOptions struct {
2119
2220type Opt func (* HTTPOptions )
2321
24- func NewHTTPClient (opts ... Opt ) * http.Client {
22+ func NewHTTPClient (ctx context. Context , opts ... Opt ) * http.Client {
2523 httpOptions := HTTPOptions {
2624 Header : make (http.Header ),
2725 }
@@ -36,7 +34,7 @@ func NewHTTPClient(opts ...Opt) *http.Client {
3634 // Disable automatic gzip: Go's default transport transparently compresses
3735 // and decompresses responses, which is incompatible with SSE streaming.
3836 // See https://github.com/docker/docker-agent/issues/1956
39- rt := newTransport ()
37+ rt := newTransport (ctx )
4038
4139 return & http.Client {
4240 Transport : & userAgentTransport {
@@ -100,26 +98,17 @@ func WithQuery(query url.Values) Opt {
10098}
10199
102100// newTransport returns an HTTP transport with automatic gzip compression disabled and using Docker Desktop proxy if available.
103- func newTransport () http.RoundTripper {
104- t , ok := http .DefaultTransport .(* http.Transport )
105- if ! ok {
106- return http .DefaultTransport
101+ func newTransport (ctx context.Context ) http.RoundTripper {
102+ // Get the base transport with Desktop proxy support from remote package
103+ rt := remote .NewTransport (ctx )
104+
105+ // If it's an http.Transport, disable compression for SSE streaming compatibility
106+ if transport , ok := rt .(* http.Transport ); ok {
107+ transport .DisableCompression = true
108+ return transport
107109 }
108- transport := t .Clone ()
109-
110- if desktop .IsDockerDesktopRunning (context .Background ()) {
111- // Route all traffic through Docker Desktop's HTTP proxy socket
112- // Set a dummy proxy URL - the actual connection happens via DialContext
113- transport .Proxy = http .ProxyURL (& url.URL {
114- Scheme : "http" ,
115- })
116- // Override the dialer to connect to the Unix socket for the proxy
117- transport .DialContext = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
118- return socket .DialUnix (desktop .Paths ().ProxySocket )
119- }
120- }
121- transport .DisableCompression = true
122- return transport
110+
111+ return rt
123112}
124113
125114type userAgentTransport struct {
0 commit comments