use http.DefaultClient (#2530)

default client already handles proxy
This commit is contained in:
Michael Yang 2024-02-20 15:34:47 -08:00 committed by GitHub
parent 4613a080e7
commit 897b213468
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 52 deletions

View file

@ -21,7 +21,7 @@ import (
type Client struct {
base *url.URL
http http.Client
http *http.Client
}
func checkError(resp *http.Response, body []byte) error {
@ -66,30 +66,13 @@ func ClientFromEnvironment() (*Client, error) {
}
}
client := Client{
return &Client{
base: &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(host, port),
},
}
mockRequest, err := http.NewRequest(http.MethodHead, client.base.String(), nil)
if err != nil {
return nil, err
}
proxyURL, err := http.ProxyFromEnvironment(mockRequest)
if err != nil {
return nil, err
}
client.http = http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
},
}
return &client, nil
http: http.DefaultClient,
}, nil
}
func (c *Client) do(ctx context.Context, method, path string, reqData, respData any) error {