Skip to content

Commit b214926

Browse files
Update workspace network client helpers
1 parent 615b2a9 commit b214926

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
package network
22

33
import (
4+
"context"
45
"net"
56
"net/http"
67
"path/filepath"
78
"time"
89
)
910

10-
// GetClient returns a new HTTP client that uses a DevPod network socket for communication.
11-
func GetClient() *http.Client {
12-
// Set up HTTP transport that uses our network socket.
11+
// Dial returns a net.Conn to the network proxy socket.
12+
func Dial() (net.Conn, error) {
1313
socketPath := filepath.Join(RootDir, NetworkProxySocket)
14-
transport := &http.Transport{
14+
return net.Dial("unix", socketPath)
15+
}
16+
17+
// GetCOntextDialer returns ContextDialer interface function that uses our network socket.
18+
func GetContextDialer() func(ctx context.Context, addr string) (net.Conn, error) {
19+
return func(ctx context.Context, addr string) (net.Conn, error) {
20+
return Dial()
21+
}
22+
}
23+
24+
// GetHTTPTransport returns http.Transport that uses our network socket for HTTP requests.
25+
func GetHTTPTransport() *http.Transport {
26+
// Set up HTTP transport that uses our network socket.
27+
return &http.Transport{
1528
Dial: func(network, addr string) (net.Conn, error) {
16-
return net.Dial("unix", socketPath)
29+
return Dial()
1730
},
1831
}
32+
}
1933

20-
client := &http.Client{
21-
Transport: transport,
22-
Timeout: 30 * time.Second, // TODO: extract this to config
34+
// GetClient returns a new HTTP client that uses our network socket for transport.
35+
func GetHTTPClient() *http.Client {
36+
return &http.Client{
37+
Transport: GetHTTPTransport(),
38+
Timeout: 30 * time.Second,
2339
}
24-
25-
return client
2640
}

0 commit comments

Comments
 (0)