Replace usage of http.DefaultClient and http.DefaultTransport (#104135)

Remove usage of http.DefaultClient and http.DefaultTransport

Part of grafana/data-sources#484
This commit is contained in:
beejeebus
2025-05-09 13:26:39 -04:00
committed by GitHub
parent 8f4b2bbece
commit 8f79e4882f
18 changed files with 120 additions and 44 deletions
+1 -9
View File
@@ -3,7 +3,6 @@ package cloudwatch
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
@@ -324,14 +323,7 @@ func (ds *DataSource) newSession(region string) (*session.Session, error) {
// only update the transport to try to avoid the issue mentioned here https://github.com/grafana/grafana/issues/46365
// also, 'sess' is cached and reused, so the first time it might have the transport not set, the following uses it will
if sess.Config.HTTPClient.Transport == nil {
// following go standard library logic (https://pkg.go.dev/net/http#Client), if no Transport is provided,
// then we use http.DefaultTransport
defTransport, ok := http.DefaultTransport.(*http.Transport)
if !ok {
// this should not happen but validating just in case
return nil, errors.New("default http client transport is not of type http.Transport")
}
sess.Config.HTTPClient.Transport = defTransport.Clone()
sess.Config.HTTPClient.Transport = httpclient.NewHTTPTransport()
}
err = proxy.New(ds.ProxyOpts).ConfigureSecureSocksHTTPProxy(sess.Config.HTTPClient.Transport.(*http.Transport))
if err != nil {