Skip to content

Commit

Permalink
use custom http.RoundTripper for auth client
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Dec 4, 2024
1 parent d012651 commit 5588720
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internalsdk/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,35 @@ type AuthClient interface {
Healthz(ctx context.Context) (bool, error)
}

type serialTransport []http.RoundTripper

func (tr serialTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
for _, rt := range tr {
resp, err = rt.RoundTrip(req)
if err == nil {
return
}
log.Debugf("Error roundtripping request to %v, continuing to next transport", req.URL)
}
log.Errorf("Unable to roundtrip request to %v, out of transports", req.URL)
return
}

// NewClient creates a new instance of AuthClient
func NewClient(baseURL string, userConfig func() common.UserConfig) AuthClient {
chained, err := proxied.ChainedNonPersistent("")
if err != nil {
log.Fatal(err)
}
frt := proxied.Fronted("auth_fronted_roundtrip", 10*time.Second)
rc := webclient.NewRESTClient(&webclient.Opts{
BaseURL: baseURL,
OnBeforeRequest: func(client *resty.Client, req *http.Request) error {
prepareUserRequest(req, userConfig())
return nil
},
HttpClient: &http.Client{
Transport: proxied.ChainedThenFronted(),
Transport: serialTransport{chained, frt},
Timeout: 30 * time.Second,
},
UserConfig: userConfig,
Expand Down

0 comments on commit 5588720

Please sign in to comment.