Skip to content

Commit b2cca6e

Browse files
committed
use go's Client object instead of DefaultClient
DefaultClient has issues resolving names like region.localhost:9090, which the standard client resolves just fine, as long as we add a custom resolver. So switch to it. x
1 parent baa4e19 commit b2cca6e

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

internal/turso/turso.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package turso
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"mime/multipart"
8+
"net"
79
"net/http"
810
"net/http/httputil"
911
"net/url"
1012
"os"
1113
"runtime"
14+
"strings"
1215

1316
"github.com/tursodatabase/turso-cli/internal/flags"
1417
)
@@ -101,7 +104,26 @@ func (t *Client) do(method, path string, body io.Reader, extraHeaders map[string
101104
if err != nil {
102105
return nil, err
103106
}
104-
resp, err := http.DefaultClient.Do(req)
107+
108+
var client = &http.Client{
109+
// go seems to have issues resolving things like region.localhost:9090, while curl works fine.
110+
// Make sure we can get it to work in those cases by resolving it manually.
111+
Transport: &http.Transport{
112+
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
113+
host, port, err := net.SplitHostPort(addr)
114+
if err != nil {
115+
return nil, err
116+
}
117+
118+
if strings.HasSuffix(host, ".localhost") {
119+
return (&net.Dialer{}).DialContext(ctx, network, net.JoinHostPort("127.0.0.1", port))
120+
}
121+
122+
return (&net.Dialer{}).DialContext(ctx, network, addr)
123+
},
124+
},
125+
}
126+
resp, err := client.Do(req)
105127
if err != nil {
106128
return nil, err
107129
}

0 commit comments

Comments
 (0)